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