Fixed 6634 (false positive: dereferencing null pointer in a sizeof operation)

This commit is contained in:
Daniel Marjamäki 2015-04-20 13:46:02 +02:00
parent 2681b0e56e
commit bdc024bd7c
2 changed files with 12 additions and 0 deletions

View File

@ -312,6 +312,11 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
const bool printInconclusive = (_settings->inconclusive);
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "sizeof|decltype|typeid|typeof (")) {
tok = tok->next()->link();
continue;
}
const Variable *var = tok->variable();
if (!var || !var->isPointer() || tok == var->nameToken())
continue;

View File

@ -1737,6 +1737,13 @@ private:
" *p = 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
// sizeof
check("void f() {\n"
" int *pointer = NULL;\n"
" pointer = func(sizeof pointer[0]);\n"
"}", false, "test.cpp", false);
ASSERT_EQUALS("", errout.str());
}
// Test CheckNullPointer::nullConstantDereference