Fixed #902 (false positive: uninitialized variable when variable is initialized in macro)

This commit is contained in:
Daniel Marjamäki 2009-11-06 16:02:13 +01:00
parent 58c54d2ed4
commit 53f7b12b4f
2 changed files with 28 additions and 0 deletions

View File

@ -1343,6 +1343,17 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token
}
}
if (tok->str() == "return")
{
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
{
if (tok2->str() == ";")
return 0;
if (tok2->varId() == varid)
break;
}
}
if (tok->varId() == varid)
{
if (Token::simpleMatch(tok->previous(), "return"))

View File

@ -1010,6 +1010,23 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
// goto..
checkUninitVar("void foo(int x)\n"
"{\n"
" long b;\n"
" if (g()) {\n"
" b =2;\n"
" goto found;\n"
" }\n"
"\n"
" return;\n"
"\n"
"found:\n"
" int a = b;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// if..
checkUninitVar("static void foo()\n"
"{\n"