Fixed #4893 (FP Uninitialized variable on sizeof of itself)
This commit is contained in:
parent
bafdb80110
commit
2ef0a40aec
|
@ -1531,7 +1531,7 @@ void CheckUninitVar::checkRhs(const Token *tok, const Variable &var, const std::
|
||||||
while (NULL != (tok = tok->next())) {
|
while (NULL != (tok = tok->next())) {
|
||||||
if (tok->str() == "=")
|
if (tok->str() == "=")
|
||||||
rhs = true;
|
rhs = true;
|
||||||
if (rhs && tok->varId() == var.varId()) {
|
else if (rhs && tok->varId() == var.varId()) {
|
||||||
if (membervar.empty() && isVariableUsage(tok, var.isPointer(), _tokenizer->isCPP()))
|
if (membervar.empty() && isVariableUsage(tok, var.isPointer(), _tokenizer->isCPP()))
|
||||||
uninitvarError(tok, tok->str());
|
uninitvarError(tok, tok->str());
|
||||||
else if (!membervar.empty() && isMemberVariableUsage(tok, var.isPointer(), membervar))
|
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)
|
if (indent == 0)
|
||||||
break;
|
break;
|
||||||
--indent;
|
--indent;
|
||||||
}
|
} else if (Token::simpleMatch(tok, "sizeof ("))
|
||||||
|
tok = tok->next()->link();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2352,6 +2352,12 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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
|
// Ticket #3486 - Don't crash garbage code
|
||||||
checkUninitVar2("void f()\n"
|
checkUninitVar2("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue