chrisdangelo created this revision. chrisdangelo added a reviewer: NoQ. Herald added subscribers: manas, steakhal, ASDenysPetrov, martong, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun. chrisdangelo requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This change clarifies the message provided when the analyzer catches the use of memory that is allocated with size zero. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D111655 Files: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp clang/test/Analysis/NewDelete-checker-test.cpp clang/test/Analysis/malloc.c
Index: clang/test/Analysis/malloc.c =================================================================== --- clang/test/Analysis/malloc.c +++ clang/test/Analysis/malloc.c @@ -261,23 +261,23 @@ void CheckUseZeroAllocated1() { int *p = malloc(0); - *p = 1; // expected-warning {{Use of zero-allocated memory}} + *p = 1; // expected-warning {{Use of memory allocated with size zero}} free(p); } char CheckUseZeroAllocated2() { char *p = alloca(0); - return *p; // expected-warning {{Use of zero-allocated memory}} + return *p; // expected-warning {{Use of memory allocated with size zero}} } char CheckUseZeroWinAllocated2() { char *p = _alloca(0); - return *p; // expected-warning {{Use of zero-allocated memory}} + return *p; // expected-warning {{Use of memory allocated with size zero}} } void UseZeroAllocated(int *p) { if (p) - *p = 7; // expected-warning {{Use of zero-allocated memory}} + *p = 7; // expected-warning {{Use of memory allocated with size zero}} } void CheckUseZeroAllocated3() { int *p = malloc(0); @@ -287,39 +287,39 @@ void f(char); void CheckUseZeroAllocated4() { char *p = valloc(0); - f(*p); // expected-warning {{Use of zero-allocated memory}} + f(*p); // expected-warning {{Use of memory allocated with size zero}} free(p); } void CheckUseZeroAllocated5() { int *p = calloc(0, 2); - *p = 1; // expected-warning {{Use of zero-allocated memory}} + *p = 1; // expected-warning {{Use of memory allocated with size zero}} free(p); } void CheckUseZeroAllocated6() { int *p = calloc(2, 0); - *p = 1; // expected-warning {{Use of zero-allocated memory}} + *p = 1; // expected-warning {{Use of memory allocated with size zero}} free(p); } void CheckUseZeroAllocated7() { int *p = realloc(0, 0); - *p = 1; // expected-warning {{Use of zero-allocated memory}} + *p = 1; // expected-warning {{Use of memory allocated with size zero}} free(p); } void CheckUseZeroAllocated8() { int *p = malloc(8); int *q = realloc(p, 0); - *q = 1; // expected-warning {{Use of zero-allocated memory}} + *q = 1; // expected-warning {{Use of memory allocated with size zero}} free(q); } void CheckUseZeroAllocated9() { int *p = realloc(0, 0); int *q = realloc(p, 0); - *q = 1; // expected-warning {{Use of zero-allocated memory}} + *q = 1; // expected-warning {{Use of memory allocated with size zero}} free(q); } @@ -344,7 +344,7 @@ char *p = malloc(s); if (b) - *p = 1; // expected-warning {{Use of zero-allocated memory}} + *p = 1; // expected-warning {{Use of memory allocated with size zero}} free(p); } @@ -372,7 +372,7 @@ char *q = realloc(p, s); if (b) - *q = 1; // expected-warning {{Use of zero-allocated memory}} + *q = 1; // expected-warning {{Use of memory allocated with size zero}} free(q); } Index: clang/test/Analysis/NewDelete-checker-test.cpp =================================================================== --- clang/test/Analysis/NewDelete-checker-test.cpp +++ clang/test/Analysis/NewDelete-checker-test.cpp @@ -105,13 +105,13 @@ void testUseZeroAlloc1() { int *p = (int *)operator new(0); - *p = 1; // newdelete-warning {{Use of zero-allocated memory}} + *p = 1; // newdelete-warning {{Use of memory allocated with size zero}} delete p; } int testUseZeroAlloc2() { int *p = (int *)operator new[](0); - return p[0]; // newdelete-warning {{Use of zero-allocated memory}} + return p[0]; // newdelete-warning {{Use of memory allocated with size zero}} delete[] p; } @@ -119,7 +119,7 @@ void testUseZeroAlloc3() { int *p = new int[0]; - f(*p); // newdelete-warning {{Use of zero-allocated memory}} + f(*p); // newdelete-warning {{Use of memory allocated with size zero}} delete[] p; } Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -2471,7 +2471,8 @@ categories::MemoryError)); auto R = std::make_unique<PathSensitiveBugReport>( - *BT_UseZerroAllocated[*CheckKind], "Use of zero-allocated memory", N); + *BT_UseZerroAllocated[*CheckKind], + "Use of memory allocated with size zero", N); R->addRange(Range); if (Sym) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits