Skip to content

Commit

Permalink
Fix #12355 FP uninitvar, legacyUninitvar with direct array init (danm…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jan 17, 2024
1 parent fa802ce commit 3d8e2ec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/checkuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set<std::string>
tok = tok->next();
while (Token::simpleMatch(tok->link(), "] ["))
tok = tok->link()->next();
if (Token::Match(tok->link(), "] =|{"))
if (Token::Match(tok->link(), "] =|{|("))
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2309,12 +2309,12 @@ void Variable::evaluate(const Settings* settings)
{
// Is there initialization in variable declaration
const Token *initTok = mNameToken ? mNameToken->next() : nullptr;
while (Token::Match(initTok, "[|(")) {
while (Token::Match(initTok, "[")) {
initTok = initTok->link()->next();
if (Token::simpleMatch(initTok, ")"))
initTok = initTok->next();
}
if (Token::Match(initTok, "=|{") || (initTok && initTok->isSplittedVarDeclEq()))
if (Token::Match(initTok, "[={(]") || (initTok && initTok->isSplittedVarDeclEq()))
setFlag(fIsInit, true);

if (!settings)
Expand Down
15 changes: 15 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,13 @@ class TestUninitVar : public TestFixture {
" return a[0];\n"
"}\n");
ASSERT_EQUALS("", errout.str());

checkUninitVar("int f() {\n" // #12355
" const int x[10](1, 2);\n"
" if (x[0] == 1) {}\n"
" return x[0];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void uninitvar_pointertoarray() {
Expand Down Expand Up @@ -6379,6 +6386,14 @@ class TestUninitVar : public TestFixture {
" char* p = new (buf) char[100];\n"
"}\n");
ASSERT_EQUALS("", errout.str());

// #12355
valueFlowUninit("int f() {\n"
" const int x[10](1, 2);\n"
" if (x[0] == 1) {}\n"
" return x[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 3d8e2ec

Please sign in to comment.