Fix #12082 FP uninitvar for assignment to array member in conditional (#5570)

This commit is contained in:
chrchr-github 2023-10-18 18:50:49 +02:00 committed by GitHub
parent 285ef96b5b
commit 09f426d980
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -3249,9 +3249,11 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings
ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings, bool cpp)
{
const Token* const parent = tok->astParent();
const Token* parent = tok->astParent();
if (indirect > 0 && parent) {
if (Token::Match(parent, "%assign%") && astIsRHS(tok))
while (Token::simpleMatch(parent, "[") && parent->astParent())
parent = parent->astParent();
if (Token::Match(parent, "%assign%") && (astIsRHS(tok) || astIsLHS(parent->astOperand1())))
return ExprUsage::NotUsed;
if (parent->isConstOp())
return ExprUsage::NotUsed;

View File

@ -6289,6 +6289,14 @@ private:
" foo(q);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: q\n", errout.str());
valueFlowUninit("int g();\n" // #12082
"void f() {\n"
" int a[1], b[1];\n"
" while (a[0] = g()) {}\n"
" if ((b[0] = g()) == 0) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value