Fix uninitdata regression (#5179)

This commit is contained in:
chrchr-github 2023-06-21 21:19:22 +02:00 committed by GitHub
parent 16198a47fa
commit 4eebf2e733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -1253,7 +1253,7 @@ const Token* CheckUninitVar::isVariableUsage(bool cpp, const Token *vartok, cons
const Token* deref = derefValue->astOperand1();
while (deref && deref->isCast())
deref = deref->astOperand1();
if (deref == vartok)
if (deref == vartok || Token::simpleMatch(deref, "+"))
return nullptr;
}
if (alloc != NO_ALLOC && astIsRhs(valueExpr))

View File

@ -2080,6 +2080,13 @@ private:
" return p;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f(int n) {\n"
" int* p = (int*)malloc(n * sizeof(int));\n"
" for (int i = 0; i < n; ++i)\n"
" *(p + i) = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
// class / struct..