Skip to content

Commit 4eebf2e

Browse files
Fix uninitdata regression (#5179)
1 parent 16198a4 commit 4eebf2e

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/checkuninitvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ const Token* CheckUninitVar::isVariableUsage(bool cpp, const Token *vartok, cons
12531253
const Token* deref = derefValue->astOperand1();
12541254
while (deref && deref->isCast())
12551255
deref = deref->astOperand1();
1256-
if (deref == vartok)
1256+
if (deref == vartok || Token::simpleMatch(deref, "+"))
12571257
return nullptr;
12581258
}
12591259
if (alloc != NO_ALLOC && astIsRhs(valueExpr))

test/testuninitvar.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,13 @@ class TestUninitVar : public TestFixture {
20802080
" return p;\n"
20812081
"}\n");
20822082
ASSERT_EQUALS("", errout.str());
2083+
2084+
checkUninitVar("void f(int n) {\n"
2085+
" int* p = (int*)malloc(n * sizeof(int));\n"
2086+
" for (int i = 0; i < n; ++i)\n"
2087+
" *(p + i) = 0;\n"
2088+
"}\n");
2089+
ASSERT_EQUALS("", errout.str());
20832090
}
20842091

20852092
// class / struct..

0 commit comments

Comments
 (0)