Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12355 FP uninitvar, legacyUninitvar with direct array init #5885

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading