Skip to content

Commit

Permalink
Fix #12394 FP uninitvar with reference to first array struct element (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Feb 21, 2024
1 parent 9541971 commit 8c729fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
tok2 = skipRedundantPtrOp(tok2, tok2->astParent());

if (tok2->astParent() && tok2->astParent()->isAssignmentOp()) {
if ((indirect == 0 || tok2 != tok) && tok2 == tok2->astParent()->astOperand1())
if (((indirect == 0 || tok2 != tok) || (indirect == 1 && tok2->str() == ".")) && tok2 == tok2->astParent()->astOperand1())
return true;
// Check if assigning to a non-const lvalue
const Variable * var = getLHSVariable(tok2->astParent());
Expand Down
8 changes: 8 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6406,6 +6406,14 @@ class TestUninitVar : public TestFixture {
" f(&b);\n"
"}\n");
ASSERT_EQUALS("", errout.str());

valueFlowUninit("struct S { int x; };\n" // #12394
"int f() {\n"
" struct S s[1];\n"
" s->x = 0;\n"
" return s[0].x;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

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

0 comments on commit 8c729fe

Please sign in to comment.