Fixed #889 (false positive: uninitialized variable)

This commit is contained in:
Daniel Marjamäki 2009-11-02 16:28:15 +01:00
parent 3e4dd22eed
commit 4abbe9ffd4
2 changed files with 14 additions and 3 deletions

View File

@ -1287,11 +1287,14 @@ static const Token *uninitvar_checkscope(const Token *tok, const unsigned int va
}
}
if (Token::Match(tok, "%varid% =", varid))
if (Token::Match(tok, "%varid%", varid))
{
if (Token::simpleMatch(tok->previous(), ">>") || Token::simpleMatch(tok->next(), "="))
{
init = true;
return 0;
}
}
if (Token::Match(tok, "%var% ("))
{

View File

@ -973,6 +973,14 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("int a()\n"
"{\n"
" int ret;\n"
" std::cin >> ret;\n"
" return ret;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// if..
checkUninitVar("static void foo()\n"
"{\n"