Fixed #936 (false positive: uninitialized variable '.. else return; .. ')

This commit is contained in:
Daniel Marjamäki 2009-11-14 20:37:54 +01:00
parent 91433587d2
commit ebf907cbc0
2 changed files with 14 additions and 0 deletions

View File

@ -1366,7 +1366,10 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
{
if (tok2->str() == ";")
{
init = true;
return 0;
}
if (tok2->varId() == varid)
break;
}

View File

@ -1096,6 +1096,17 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("int foo(int x)\n"
"{\n"
" int i;\n"
" if (one())\n"
" i = 1;\n"
" else\n"
" return 3;\n"
" return i;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// switch..
checkUninitVar("char * f()\n"
"{\n"