CheckNullPointer::isPointerDeRef: Tweaks to reduce false warnings when inconclusive is used.

This commit is contained in:
Daniel Marjamäki 2011-12-11 08:48:55 +01:00
parent 497c54a1a7
commit ffb5d107be
2 changed files with 10 additions and 1 deletions

View File

@ -83,7 +83,7 @@ static std::string bufferOverrunMessage(std::string varnames)
std::string errmsg("Buffer access out-of-bounds");
if (!varnames.empty())
errmsg += ": " + varnames;
return errmsg;
}

View File

@ -254,6 +254,15 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown)
if (Token::Match(tok->previous(), "delete %var%") || Token::Match(tok->tokAt(-3), "delete [ ] %var%"))
return false;
// OK to check if pointer is null
// OK to take address of pointer
if (Token::Match(tok->previous(), "!|& %var% )|,|&&|%oror%"))
return false;
// OK to pass pointer to function
if (Token::Match(tok->previous(), ", %var% [,)]"))
return false;
// unknown if it's a dereference
unknown = true;