Fixed #2134 (sizeof(*list) complains of null pointer dereference)

This commit is contained in:
Daniel Marjamäki 2010-10-26 18:26:02 +02:00
parent b6106ddf72
commit 9370f552ac
2 changed files with 13 additions and 2 deletions

View File

@ -2495,7 +2495,7 @@ void CheckOther::nullPointerByDeRefAndChec()
// Check that variable is a pointer..
const Token *decltok = Token::findmatch(_tokenizer->tokens(), "%varid%", varid);
if (!Token::Match(decltok->tokAt(-3), "[;,(] %type% *"))
if (!Token::Match(decltok->tokAt(-3), "[{};,(] %type% *"))
continue;
for (const Token *tok1 = tok->previous(); tok1 && tok1 != decltok; tok1 = tok1->previous())
@ -2516,7 +2516,7 @@ void CheckOther::nullPointerByDeRefAndChec()
break;
}
// dereference in function call
else if (Token::Match(tok1->tokAt(-2), "[(,] *"))
else if (Token::Match(tok1->tokAt(-3), "!!sizeof [(,] *"))
{
nullPointerError(tok1, varname, tok->linenr());
}

View File

@ -695,6 +695,17 @@ private:
" if (a) { }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// ticket #2134 - sizeof doesn't dereference
checkNullPointer("void f() {\n"
" int c = 1;\n"
" int *list = NULL;\n"
" sizeof(*list);\n"
" if (!list)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void nullpointer2()