CheckNullPointer::isPointerDeref: better checking if pointer is not dereferenced

This commit is contained in:
Daniel Marjamäki 2011-12-15 17:01:39 +01:00
parent 3a432fa959
commit 9e54714894
1 changed files with 10 additions and 2 deletions

View File

@ -252,7 +252,7 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown)
// This is most useful in inconclusive checking
if (inconclusive) {
// Not a dereference..
if (Token::Match(tok->previous(), "[;{}] %var% ="))
if (Token::Match(tok->previous(), "[;{}(] %var% ="))
return false;
// OK to delete a null
@ -265,7 +265,15 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown)
return false;
// OK to pass pointer to function
if (Token::Match(tok->previous(), ", %var% [,)]"))
if (Token::Match(tok->previous(), "[(,] %var% [,)]"))
return false;
// Compare pointer
if (Token::Match(tok->previous(), "(|&&|%oror%|==|!= %var% &&|%oror%|)"))
return false;
// Taking address
if (Token::Match(tok->previous(), "return|= %var% ;"))
return false;
// unknown if it's a dereference