[clang] f3ec9d8 - [analyzer] Fix non-obvious analyzer warning: Use of zero-allocated memory.
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 12 10:41:09 PDT 2021
Author: Artem Dergachev
Date: 2021-10-12T10:41:00-07:00
New Revision: f3ec9d8501c91c22c1578470e638c74120f60667
URL: https://github.com/llvm/llvm-project/commit/f3ec9d8501c91c22c1578470e638c74120f60667
DIFF: https://github.com/llvm/llvm-project/commit/f3ec9d8501c91c22c1578470e638c74120f60667.diff
LOG: [analyzer] Fix non-obvious analyzer warning: Use of zero-allocated memory.
Clarify the message provided when the analyzer catches the use of memory
that is allocated with size zero.
Differential Revision: https://reviews.llvm.org/D111655
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/test/Analysis/NewDelete-checker-test.cpp
clang/test/Analysis/malloc.c
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 9899298b348a0..5f505f8a03719 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2471,7 +2471,8 @@ void MallocChecker::HandleUseZeroAlloc(CheckerContext &C, SourceRange Range,
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) {
diff --git a/clang/test/Analysis/NewDelete-checker-test.cpp b/clang/test/Analysis/NewDelete-checker-test.cpp
index 86df9d01dfb01..5a06c8327f717 100644
--- a/clang/test/Analysis/NewDelete-checker-test.cpp
+++ b/clang/test/Analysis/NewDelete-checker-test.cpp
@@ -105,13 +105,13 @@ void testNewInvalidationPlacement(PtrWrapper *w) {
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 f(int);
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;
}
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c
index add5dc7fe8c21..ef275ae5028b6 100644
--- a/clang/test/Analysis/malloc.c
+++ b/clang/test/Analysis/malloc.c
@@ -261,23 +261,23 @@ void CheckUseZeroAllocatedNoWarn4() {
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 CheckUseZeroAllocated3() {
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 @@ void CheckUseZeroAllocatedPathWarn(_Bool b) {
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 @@ void CheckUseZeroReallocatedPathWarn(_Bool b) {
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);
}
More information about the cfe-commits
mailing list