Skip to content

Commit

Permalink
Fix #12473 FN uninitvar with pointer member (regression) (danmar#6039)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Feb 26, 2024
1 parent 950e894 commit 91f15aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ void CheckUninitVar::valueFlowUninit()
(!isVariableChangedByFunctionCall(v->tokvalue, v->indirect, mSettings, &inconclusive) || inconclusive))
continue;
if (usage != ExprUsage::Used) {
if (!(Token::Match(tok->astParent(), ". %name% (") && uninitderef) &&
if (!(Token::Match(tok->astParent(), ". %name% (|[") && uninitderef) &&
isVariableChanged(tok, v->indirect, mSettings, mTokenizer->isCPP()))
continue;
if (isVariableChangedByFunctionCall(tok, v->indirect, mSettings, &inconclusive) || inconclusive)
Expand Down
7 changes: 7 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6414,6 +6414,13 @@ class TestUninitVar : public TestFixture {
" return s[0].x;\n"
"}\n");
ASSERT_EQUALS("", errout.str());

valueFlowUninit("struct S { int* p; };\n" // #12473
"void f() {\n"
" struct S s;\n"
" s.p[0] = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s.p\n", errout.str());
}

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

0 comments on commit 91f15aa

Please sign in to comment.