Fixed 6634 (false positive: dereferencing null pointer in a sizeof operation)
This commit is contained in:
parent
2681b0e56e
commit
bdc024bd7c
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue