Fixed #904 (false positive: uninitialized variable)

This commit is contained in:
Daniel Marjamäki 2009-11-06 16:50:02 +01:00
parent 53f7b12b4f
commit 7397bfc765
2 changed files with 14 additions and 1 deletions

View File

@ -1430,6 +1430,13 @@ void CheckOther::uninitvar()
// Is it an array? // Is it an array?
const bool array(tok->next()->str() == "["); const bool array(tok->next()->str() == "[");
if (array)
{
// is the array initialized?
if (Token::simpleMatch(tok->next(), "[ ] =") ||
Token::Match(tok->next(), "[ %any% ] ="))
continue;
}
// check if variable is accessed uninitialized.. // check if variable is accessed uninitialized..
bool init = false; bool init = false;

View File

@ -944,7 +944,6 @@ private:
// Check for redundant code.. // Check for redundant code..
Settings settings; Settings settings;
settings._checkCodingStyle = true;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.uninitvar(); checkOther.uninitvar();
} }
@ -1109,6 +1108,13 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("void f()\n"
"{\n"
" char c[50] = \"\";\n"
" strcat(c, \"test\");\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f()\n" checkUninitVar("void f()\n"
"{\n" "{\n"
" char s[20];\n" " char s[20];\n"