Skip to content

Commit

Permalink
Fix #11804 FP uninitvar for array in struct in struct
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Aug 11, 2023
1 parent 6ad5538 commit 98afe8e
Show file tree
Hide file tree
Showing 2 changed files with 22 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 @@ -1579,7 +1579,7 @@ static bool isLeafDot(const Token* tok)
const Token * parent = tok->astParent();
if (!Token::simpleMatch(parent, "."))
return false;
if (parent->astOperand2() == tok)
if (parent->astOperand2() == tok && !Token::simpleMatch(parent->astParent(), "."))
return true;
return isLeafDot(parent);
}
Expand Down
21 changes: 21 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6139,6 +6139,27 @@ class TestUninitVar : public TestFixture {
" int& r = *p;\n"
"}\n");
ASSERT_EQUALS("", errout.str());

valueFlowUninit("void f(std::stringstream& ss) {\n" // #11805
" int x;\n"
" int* p = &x;\n"
" ss >> *p;\n"
"}\n"
"void g() {\n"
" int x;\n"
" int* p = &x;\n"
" int& r = *p;\n"
"}\n");
ASSERT_EQUALS("", errout.str());

valueFlowUninit("struct S1 { char a[10]; };\n" // #11804
"struct S2 { struct S1 s1; };\n"
"void init(char* c);\n"
"void f() {\n"
" struct S2 s2;\n"
" init(s2.s1.a);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

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

0 comments on commit 98afe8e

Please sign in to comment.