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

@ -1349,6 +1349,8 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token
return tok;
if (Token::simpleMatch(tok->previous(), "="))
{
if (!Token::Match(tok->tokAt(-3), ". %var% ="))
{
if (!Token::Match(tok->tokAt(-3), "[;{}] %var% ="))
return tok;
@ -1361,6 +1363,7 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token
return tok;
}
}
}
if (pointer && Token::simpleMatch(tok->next(), "."))
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"