Fixed #4893 (FP Uninitialized variable on sizeof of itself)

This commit is contained in:
Daniel Marjamäki 2013-07-06 08:52:47 +02:00
parent bafdb80110
commit 2ef0a40aec
2 changed files with 9 additions and 2 deletions

View File

@ -1531,7 +1531,7 @@ void CheckUninitVar::checkRhs(const Token *tok, const Variable &var, const std::
while (NULL != (tok = tok->next())) {
if (tok->str() == "=")
rhs = true;
if (rhs && tok->varId() == var.varId()) {
else if (rhs && tok->varId() == var.varId()) {
if (membervar.empty() && isVariableUsage(tok, var.isPointer(), _tokenizer->isCPP()))
uninitvarError(tok, tok->str());
else if (!membervar.empty() && isMemberVariableUsage(tok, var.isPointer(), membervar))
@ -1545,7 +1545,8 @@ void CheckUninitVar::checkRhs(const Token *tok, const Variable &var, const std::
if (indent == 0)
break;
--indent;
}
} else if (Token::simpleMatch(tok, "sizeof ("))
tok = tok->next()->link();
}
}

View File

@ -2352,6 +2352,12 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n"
" A *a;\n"
" a = malloc(sizeof(*a));\n"
"}");
ASSERT_EQUALS("", errout.str());
// Ticket #3486 - Don't crash garbage code
checkUninitVar2("void f()\n"
"{\n"