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;
|
return tok;
|
||||||
|
|
||||||
if (Token::simpleMatch(tok->previous(), "="))
|
if (Token::simpleMatch(tok->previous(), "="))
|
||||||
|
{
|
||||||
|
if (!Token::Match(tok->tokAt(-3), ". %var% ="))
|
||||||
{
|
{
|
||||||
if (!Token::Match(tok->tokAt(-3), "[;{}] %var% ="))
|
if (!Token::Match(tok->tokAt(-3), "[;{}] %var% ="))
|
||||||
return tok;
|
return tok;
|
||||||
|
@ -1361,6 +1363,7 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token
|
||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (pointer && Token::simpleMatch(tok->next(), "."))
|
if (pointer && Token::simpleMatch(tok->next(), "."))
|
||||||
return tok;
|
return tok;
|
||||||
|
|
|
@ -1003,6 +1003,13 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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..
|
// if..
|
||||||
checkUninitVar("static void foo()\n"
|
checkUninitVar("static void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue