Fixed #929 (Uninitialized variable false positive)

This commit is contained in:
Daniel Marjamäki 2009-11-10 18:05:55 +01:00
parent 51f983629b
commit e0b1303b50
2 changed files with 25 additions and 0 deletions

View File

@ -1203,6 +1203,17 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token
return 0;
}
if (Token::Match(tok, "= {"))
{
tok = tok->next()->link();
if (!tok)
{
init = true;
return 0;
}
continue;
}
if (tok->str() == "if")
{
bool canInit = false;

View File

@ -1048,6 +1048,20 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("int foo()\n"
"{\n"
" int i;\n"
" if (x)\n"
" i = 22;\n"
" else\n"
" {\n"
" char *y = {0};\n"
" i = 33;\n"
" }\n"
" return i;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("static void foo()\n"
"{\n"
" Foo *p;\n"