Skip to content

Commit

Permalink
Fix #12459 FP uninitialized variable, pointer passed to constructor (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Feb 27, 2024
1 parent 86994c5 commit 18583ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3293,7 +3293,7 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings
} else if (ftok->str() == "{") {
return indirect == 0 ? ExprUsage::Used : ExprUsage::Inconclusive;
} else if (ftok->variable() && ftok == ftok->variable()->nameToken()) { // variable init/constructor call
if (ftok->variable()->type() && ftok->variable()->type()->needInitialization == Type::NeedInitialization::True)
if (ftok->variable()->type() && ftok->variable()->type()->classScope && ftok->variable()->type()->classScope->numConstructors == 0)
return ExprUsage::Used;
if (ftok->variable()->isStlType() || (ftok->variable()->valueType() && ftok->variable()->valueType()->container)) // STL types or containers don't initialize external variables
return ExprUsage::Used;
Expand Down
10 changes: 10 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7384,6 +7384,16 @@ class TestUninitVar : public TestFixture {
"[test.cpp:8]: (error) Uninitialized variable: i\n"
"[test.cpp:12]: (error) Uninitialized variable: i\n",
errout.str());

valueFlowUninit("struct S {\n"
" S(char**);\n"
" int i;\n"
"};\n"
"void f() {\n"
" char* p;\n"
" S s(&p);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void uninitvar_memberfunction() {
Expand Down

0 comments on commit 18583ca

Please sign in to comment.