Uninitialized variables: Fixed fp when initializing struct with function in loop body

This commit is contained in:
Daniel Marjamäki 2013-04-10 20:46:44 +02:00
parent 96a5429cee
commit 7fdaba43ed
2 changed files with 10 additions and 0 deletions

View File

@ -1461,6 +1461,8 @@ bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const
if (isMemberVariableUsage(tok, var.isPointer(), membervar))
usetok = tok;
else if (Token::Match(tok->previous(), "[(,] %var% [,)]"))
return true;
} else {
if (isVariableUsage(tok, var.isPointer(), _tokenizer->isCPP()))
usetok = tok;

View File

@ -2731,6 +2731,14 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
// for
checkUninitVar2("struct AB { int a; };\n"
"void f() {\n"
" struct AB ab;\n"
" while (x) { clear(ab); z = ab.a; }\n"
"}");
ASSERT_EQUALS("", errout.str());
// address of member
checkUninitVar2("struct AB { int a[10]; int b; };\n"
"void f() {\n"