Skip to content

Commit

Permalink
Fix 12460: False positive: uninitialized variable, conditional initia…
Browse files Browse the repository at this point in the history
…lization, flag
  • Loading branch information
pfultz2 committed Apr 1, 2024
1 parent cd946e3 commit c3ddcad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,8 @@ namespace {
v2.intvalue += value.intvalue;
return v2;
}
if(v.isImpossible() && v.isIntValue())
return v;
if (const ValueFlow::Value* value = getImpossibleValue(expr))
return *value;
return v;
Expand Down
13 changes: 13 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6447,6 +6447,19 @@ class TestUninitVar : public TestFixture {
" s.p[0] = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s.p\n", errout_str());

// #12460
valueFlowUninit("typedef struct {\n"
" int a;\n"
"} st;\n"
"void foo(int* p, bool success) {\n"
" st myst;\n"
" if (success == 1) {\n"
" myst.a = 5;\n"
" }\n"
" if ((success == 1) && (myst.a != 0)) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

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

0 comments on commit c3ddcad

Please sign in to comment.