This commit is contained in:
Daniel Marjamäki 2009-11-15 20:26:07 +01:00
parent 2cbda0cfe4
commit d866c174cf
2 changed files with 11 additions and 1 deletions

View File

@ -1300,8 +1300,11 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token
}
}
if (Token::Match(tok, "%varid%", varid))
if (tok->varId() == varid)
{
if (pointer && Token::Match(tok->tokAt(-2), "[;{}] *"))
return tok;
if (Token::simpleMatch(tok->previous(), ">>") || Token::simpleMatch(tok->next(), "="))
{
init = true;

View File

@ -973,6 +973,13 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar("static void foo()\n"
"{\n"
" int *p;\n"
" *p = 135;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar("static void foo()\n"
"{\n"
" Foo p;\n"