Fixed #2245 (False positive: Possible null pointer dereference)
This commit is contained in:
parent
8b45a0e3b5
commit
cdb685c83c
|
@ -490,6 +490,13 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
|||
break;
|
||||
}
|
||||
|
||||
// parameters to sizeof are not dereferenced
|
||||
if (Token::Match(tok2, "decltype|sizeof ("))
|
||||
{
|
||||
tok2 = tok2->next()->link();
|
||||
continue;
|
||||
}
|
||||
|
||||
// abort function..
|
||||
if (Token::simpleMatch(tok2, ") ; }") &&
|
||||
Token::Match(tok2->link()->tokAt(-2), "[;{}] %var% ("))
|
||||
|
@ -550,7 +557,7 @@ void CheckNullPointer::nullConstantDereference()
|
|||
--indentlevel;
|
||||
}
|
||||
|
||||
if (tok->str() == "(" && Token::simpleMatch(tok->previous(), "sizeof"))
|
||||
if (tok->str() == "(" && Token::Match(tok->previous(), "sizeof|decltype"))
|
||||
tok = tok->link();
|
||||
|
||||
else if (Token::simpleMatch(tok, "exit ( )"))
|
||||
|
|
|
@ -154,6 +154,14 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// ticket #2245 - sizeof doesn't dereference
|
||||
check("void f(Bar *p) {\n"
|
||||
" if (!p) {\n"
|
||||
" int sz = sizeof(p->x);\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
}
|
||||
|
||||
void nullpointer2()
|
||||
|
|
Loading…
Reference in New Issue