From bf966f523755c9f72886e90a98c15eae8d248cd8 Mon Sep 17 00:00:00 2001 From: Adam Balogh Date: Fri, 13 Jul 2018 13:44:44 +0000 Subject: [Analyzer] alpha.unix.cstring.OutOfBounds checker enable/disable fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was not possible to disable alpha.unix.cstring.OutOfBounds checker's reports since unix.Malloc checker always implicitly enabled the filter. Moreover if the checker was disabled from command line (-analyzer-disable-checker ..) the out of bounds warnings were nevertheless emitted under different checker names such as unix.cstring.NullArg, or unix.Malloc. This patch fixes the case sot that Malloc checker only enables implicitly the underlying modeling of strcpy, memcpy etc. but not the warning messages that would have been emmitted by alpha.unix.cstring.OutOfBounds Patch by: Dániel Krupp Differential Revision: https://reviews.llvm.org/D48831 llvm-svn: 337000 --- clang/test/Analysis/malloc.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'clang/test/Analysis/malloc.c') diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c index 50be4ef3ba2..3e86c29a55a 100644 --- a/clang/test/Analysis/malloc.c +++ b/clang/test/Analysis/malloc.c @@ -375,7 +375,7 @@ void CheckUseZeroReallocatedPathWarn(_Bool b) { // or inter-procedural analysis, this is a conservative answer. int *f3() { static int *p = 0; - p = malloc(12); + p = malloc(12); return p; // no-warning } @@ -384,7 +384,7 @@ int *f3() { // functions or inter-procedural analysis, this is a conservative answer. static int *p_f4 = 0; int *f4() { - p_f4 = malloc(12); + p_f4 = malloc(12); return p_f4; // no-warning } @@ -1232,7 +1232,7 @@ void radar10978247(int myValueSize) { if (myValueSize <= sizeof(stackBuffer)) buffer = stackBuffer; - else + else buffer = malloc(myValueSize); // do stuff with the buffer @@ -1246,7 +1246,7 @@ void radar10978247_positive(int myValueSize) { if (myValueSize <= sizeof(stackBuffer)) buffer = stackBuffer; - else + else buffer = malloc(myValueSize); // do stuff with the buffer @@ -1254,7 +1254,7 @@ void radar10978247_positive(int myValueSize) { return; else return; // expected-warning {{leak}} -} +} // Previously this triggered a false positive // because malloc() is known to return uninitialized memory and the binding // of 'o' to 'p->n' was not getting propertly handled. Now we report a leak. @@ -1698,7 +1698,7 @@ void testReallocEscaped(void **memory) { void *smallocNoWarn(size_t size) { if (size == 0) { return malloc(1); // this branch is never called - } + } else { return malloc(size); } @@ -1777,21 +1777,12 @@ 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); -} - void allocateSomeMemory(void *offendingParameter, void **ptr) { *ptr = malloc(1); } void testNoCrashOnOffendingParameter() { - // "extern" is necessary to avoid unrelated warnings + // "extern" is necessary to avoid unrelated warnings // on passing uninitialized value. extern void *offendingParameter; void* ptr; -- cgit v1.2.3