summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorDevin Coughlin <dcoughlin@apple.com>2018-01-20 23:11:17 +0000
committerDevin Coughlin <dcoughlin@apple.com>2018-01-20 23:11:17 +0000
commit2ff57bcd18d3514c3f5baed6d34e02f885e81b28 (patch)
treeb08dae3abff9858965590723381fed75ebb16d03 /clang/test
parent5829d8f1f7ad3bf4796615caf941d97c116d815e (diff)
downloadbcm5719-llvm-2ff57bcd18d3514c3f5baed6d34e02f885e81b28.tar.gz
bcm5719-llvm-2ff57bcd18d3514c3f5baed6d34e02f885e81b28.zip
[analyzer] Provide a check name when MallocChecker enables CStringChecker
Fix an assertion failure caused by a missing CheckName. The malloc checker enables "basic" support in the CStringChecker, which causes some CString bounds checks to be enabled. In this case, make sure that we have a valid CheckName for the BugType. llvm-svn: 323052
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Analysis/Inputs/system-header-simulator.h1
-rw-r--r--clang/test/Analysis/malloc.c9
2 files changed, 10 insertions, 0 deletions
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h b/clang/test/Analysis/Inputs/system-header-simulator.h
index 2e6f1e7d4a9..ff69a1502b9 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -32,6 +32,7 @@ typedef __typeof(sizeof(int)) size_t;
size_t strlen(const char *);
char *strcpy(char *restrict, const char *restrict);
+char *strncpy(char *dst, const char *src, size_t n);
void *memcpy(void *dst, const void *src, size_t n);
typedef unsigned long __darwin_pthread_key_t;
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c
index e08ec1b76cf..6e3f3faaa17 100644
--- a/clang/test/Analysis/malloc.c
+++ b/clang/test/Analysis/malloc.c
@@ -1777,6 +1777,15 @@ void freeFunctionPtr() {
free((void *)fnptr); // expected-warning {{Argument to free() is a function pointer}}
}
+// Enabling the malloc checker enables some of the buffer-checking portions
+// of the C-string checker.
+void cstringchecker_bounds_nocrash() {
+ char *p = malloc(2);
+ strncpy(p, "AAA", sizeof("AAA")); // expected-warning {{Size argument is greater than the length of the destination buffer}}
+
+ free(p);
+}
+
// ----------------------------------------------------------------------------
// False negatives.
OpenPOWER on IntegriCloud