Skip to content

Commit 0736f0a

Browse files
Fix #13076 FP uninitvar with unknown struct definition (danmar#7158)
1 parent 26ce3f1 commit 0736f0a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/valueflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,6 +2785,8 @@ static bool isDecayedPointer(const Token *tok)
27852785
return false;
27862786
if (!tok->astParent())
27872787
return false;
2788+
if (Token::simpleMatch(tok->astParent(), "=") && astIsRHS(tok))
2789+
return true;
27882790
if (astIsPointer(tok->astParent()) && !Token::simpleMatch(tok->astParent(), "return"))
27892791
return true;
27902792
if (tok->astParent()->isConstOp())

test/testvalueflow.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,17 @@ class TestValueFlow : public TestFixture {
743743
lifetimes = lifetimeValues(code, "return"); // don't crash
744744
ASSERT_EQUALS(true, lifetimes.empty());
745745
}
746+
747+
{
748+
const char code[] = "void f() {\n" // #13076
749+
" char a[10];\n"
750+
" struct S s = { sizeof(a), 0 };\n"
751+
" s.p = a;\n"
752+
"}\n";
753+
lifetimes = lifetimeValues(code, "= a");
754+
ASSERT_EQUALS(true, lifetimes.size() == 1);
755+
ASSERT_EQUALS(true, lifetimes.front() == "a");
756+
}
746757
}
747758

748759
void valueFlowArrayElement() {

0 commit comments

Comments
 (0)