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?
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..
bool init = false;

View File

@ -944,7 +944,6 @@ private:
// Check for redundant code..
Settings settings;
settings._checkCodingStyle = true;
CheckOther checkOther(&tokenizer, &settings, this);
checkOther.uninitvar();
}
@ -1109,6 +1108,13 @@ private:
"}\n");
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"
"{\n"
" char s[20];\n"