Fixed #897 (false positive: uninitialized variable when assigning pointer to array to struct member)

This commit is contained in:
Daniel Marjamäki 2009-11-05 21:07:04 +01:00
parent de4ca924b5
commit 442584151b
2 changed files with 17 additions and 7 deletions

View File

@ -1350,15 +1350,18 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token
if (Token::simpleMatch(tok->previous(), "="))
{
if (!Token::Match(tok->tokAt(-3), "[;{}] %var% ="))
return tok;
const unsigned int varid2 = tok->tokAt(-2)->varId();
if (varid2)
if (!Token::Match(tok->tokAt(-3), ". %var% ="))
{
const Token *tok2 = Token::findmatch(tokens, "%varid%", varid2);
if (tok2 && !Token::simpleMatch(tok2->previous(), "*"))
if (!Token::Match(tok->tokAt(-3), "[;{}] %var% ="))
return tok;
const unsigned int varid2 = tok->tokAt(-2)->varId();
if (varid2)
{
const Token *tok2 = Token::findmatch(tokens, "%varid%", varid2);
if (tok2 && !Token::simpleMatch(tok2->previous(), "*"))
return tok;
}
}
}

View File

@ -1003,6 +1003,13 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void a()\n"
"{\n"
" int x[10];\n"
" struct xyz xyz1 = { .x = x };\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// if..
checkUninitVar("static void foo()\n"
"{\n"