Fixed #9349 (FP ctuuninitvar for pointer dereferenced inside sizeof)

This commit is contained in:
Daniel Marjamäki 2019-09-12 13:29:52 +02:00
parent b8e3d3b982
commit da363c7d6f
2 changed files with 14 additions and 0 deletions

View File

@ -979,6 +979,12 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
{
bool unknown = false;
const Token *possibleParent = getAstParentSkipPossibleCastAndAddressOf(vartok, &unknown);
if (possibleParent && possibleParent->isUnaryOp("*")) {
while (possibleParent && possibleParent->isUnaryOp("*"))
possibleParent = getAstParentSkipPossibleCastAndAddressOf(possibleParent, &unknown);
if (possibleParent && Token::Match(possibleParent->previous(), "sizeof ("))
return false;
}
if (Token::Match(possibleParent, "[(,]")) {
if (unknown)
return false; // TODO: output some info message?

View File

@ -4583,6 +4583,14 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
ctu("void f(int *p) {\n"
" a = sizeof(*p);\n"
"}\n"
"int main() {\n"
" int x;\n"
" f(&x);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};