Skip to content

Commit 9f28644

Browse files
authored
Fix 12460: False positive: uninitialized variable, conditional initialization, flag (#6217)
1 parent 3de9052 commit 9f28644

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/programmemory.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,8 @@ namespace {
16811681
v2.intvalue += value.intvalue;
16821682
return v2;
16831683
}
1684+
if (v.isImpossible() && v.isIntValue())
1685+
return v;
16841686
if (const ValueFlow::Value* value = getImpossibleValue(expr))
16851687
return *value;
16861688
return v;

test/testuninitvar.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6447,6 +6447,19 @@ class TestUninitVar : public TestFixture {
64476447
" s.p[0] = 0;\n"
64486448
"}\n");
64496449
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s.p\n", errout_str());
6450+
6451+
// #12460
6452+
valueFlowUninit("typedef struct {\n"
6453+
" int a;\n"
6454+
"} st;\n"
6455+
"void foo(int* p, bool success) {\n"
6456+
" st myst;\n"
6457+
" if (success == 1) {\n"
6458+
" myst.a = 5;\n"
6459+
" }\n"
6460+
" if ((success == 1) && (myst.a != 0)) {}\n"
6461+
"}\n");
6462+
ASSERT_EQUALS("", errout_str());
64506463
}
64516464

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

0 commit comments

Comments
 (0)