Skip to content

Commit

Permalink
Fix #12082 FP uninitvar for assignment to array member in conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Oct 18, 2023
1 parent 9329772 commit 8bb4b1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3232,6 +3232,8 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings
if (!args.empty() && indirect == 0 && !addressOf)
return ExprUsage::Used;
} else if (ftok->isControlFlowKeyword()) {
if (Token::simpleMatch(ftok->astParent(), "(") && Token::simpleMatch(ftok->astParent()->astOperand2(), "="))
return ExprUsage::Inconclusive;
return ExprUsage::Used;
} else if (ftok->str() == "{") {
return indirect == 0 ? ExprUsage::Used : ExprUsage::Inconclusive;
Expand Down
9 changes: 8 additions & 1 deletion test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6288,7 +6288,14 @@ class TestUninitVar : public TestFixture {
" int &q = s;\n"
" foo(q);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: q\n", errout.str());
ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: q\n", errout.str());

valueFlowUninit("int g();\n" // #12082
"void f() {\n"
" int a[1];\n"
" while (a[0] = g()) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}

void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value
Expand Down

0 comments on commit 8bb4b1a

Please sign in to comment.