Fixed #897 (false positive: uninitialized variable when assigning pointer to array to struct member)
This commit is contained in:
parent
de4ca924b5
commit
442584151b
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue