Skip to content

Commit

Permalink
Fixed #12030 (False positive: uninitialized variable, conditional mod…
Browse files Browse the repository at this point in the history
…ification, flag)
  • Loading branch information
danmar committed Oct 6, 2023
1 parent 723ba16 commit e1ef59c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3087,7 +3087,7 @@ struct SingleValueFlowAnalyzer : ValueFlowAnalyzer {
bool stopOnCondition(const Token* condTok) const override
{
if (value.isNonValue())
return false;
return isConditional();
if (value.isImpossible())
return false;
if (isConditional() && !value.isKnown() && !value.isImpossible())
Expand Down
2 changes: 1 addition & 1 deletion test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4463,7 +4463,7 @@ class TestAutoVariables : public TestFixture {
" return *iPtr;\n"
" return 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:8]: (error) Using pointer to local variable 'x' that is out of scope.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:8]: (error) Using pointer to local variable 'x' that is out of scope.\n", "", errout.str());

// #11753
check("int main(int argc, const char *argv[]) {\n"
Expand Down
13 changes: 12 additions & 1 deletion test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3621,7 +3621,7 @@ class TestUninitVar : public TestFixture {
" a = y;\n"
" return y ? 2*a : 3*a;\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Uninitialized variable: a\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Uninitialized variable: a\n", "", errout.str());

valueFlowUninit("void f() {\n" // Don't crash
" int a;\n"
Expand Down Expand Up @@ -3683,6 +3683,17 @@ class TestUninitVar : public TestFixture {
"}", "test.c");
ASSERT_EQUALS("", errout.str());

valueFlowUninit("int set(int *x);\n" // #12030
"void foo(bool a) {\n"
" bool flag{0};\n"
" int x;\n"
" if (!a) {\n"
" flag = set(&x);\n"
" }\n"
" if (!flags && x==3) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());

valueFlowUninit("int do_something();\n"
"int set_st(int *x);\n"
"int bar();\n"
Expand Down

0 comments on commit e1ef59c

Please sign in to comment.