Skip to content

Commit 775bfe3

Browse files
committed
Fix #11023 false positive: uninitdata with delete on unused allocated array
1 parent c3665c5 commit 775bfe3

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎lib/checkuninitvar.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,9 @@ const Token* CheckUninitVarImpl::isVariableUsage(const Token *vartok, const Libr
12531253
return nullptr;
12541254
if (Token::simpleMatch(valueExpr->astParent(), "return"))
12551255
return nullptr;
1256+
// deallocating the memory does not read the data
1257+
if (!derefValue && Token::simpleMatch(valueExpr->astParent(), "delete"))
1258+
return nullptr;
12561259
}
12571260

12581261
// Passing variable to function..

‎test/testuninitvar.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,13 @@ class TestUninitVar : public TestFixture {
19411941

19421942
// alloc..
19431943
void uninitvar_alloc() {
1944+
checkUninitVar("void f()\n" // #11023
1945+
"{\n"
1946+
" char * c = new char[12];\n"
1947+
" delete [] c;\n"
1948+
"}\n");
1949+
ASSERT_EQUALS("", errout_str());
1950+
19441951
checkUninitVar("void f() {\n"
19451952
" char *s = (char *)malloc(100);\n"
19461953
" strcat(s, \"abc\");\n"

0 commit comments

Comments
 (0)