Skip to content

Commit 4db2868

Browse files
Fix #14191 FP uninitvar with conditional pointer reassignment (danmar#7875)
Co-authored-by: chrchr-github <[email protected]>
1 parent 97dfca9 commit 4db2868

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/vf_analyzers.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,8 @@ struct ValueFlowAnalyzer : Analyzer {
608608
for (const ValueFlow::Value& v:ref->astOperand1()->values()) {
609609
if (!v.isLocalLifetimeValue())
610610
continue;
611+
if (v.conditional)
612+
continue;
611613
if (lifeTok)
612614
return Action::None;
613615
lifeTok = v.tokvalue;

test/testuninitvar.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7936,6 +7936,20 @@ class TestUninitVar : public TestFixture {
79367936
" return s;\n"
79377937
"}\n");
79387938
ASSERT_EQUALS("", errout_str());
7939+
7940+
valueFlowUninit("struct S { int i; };\n" // #14191
7941+
"bool g(S*);\n"
7942+
"void f( struct S *p) {\n"
7943+
" struct S s;\n"
7944+
" if (!p) {\n"
7945+
" p = &s;\n"
7946+
" if (g(p))\n"
7947+
" return;\n"
7948+
" }\n"
7949+
" printf(\"%i\", p->i);\n"
7950+
" p = &s;\n"
7951+
"}\n");
7952+
ASSERT_EQUALS("", errout_str());
79397953
}
79407954

79417955
template<size_t size>

0 commit comments

Comments
 (0)