CheckNullPointer::isPointerDeRef: Skip inconclusive checking when --inconclusive hasn't been given.

This commit is contained in:
Daniel Marjamäki 2011-12-12 07:35:53 +01:00
parent 99d8ce3732
commit 2dbe7ca196
1 changed files with 24 additions and 18 deletions

View File

@ -218,6 +218,8 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
*/ */
bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown) bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown)
{ {
const bool inconclusive = unknown;
unknown = false; unknown = false;
// Dereferencing pointer.. // Dereferencing pointer..
@ -246,6 +248,9 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown)
tok->varId() == tok->tokAt(2)->varId()) tok->varId() == tok->tokAt(2)->varId())
return true; return true;
// Check if it's NOT a pointer dereference.
// This is most useful in inconclusive checking
if (inconclusive) {
// Not a dereference.. // Not a dereference..
if (Token::Match(tok->previous(), "[;{}] %var% =")) if (Token::Match(tok->previous(), "[;{}] %var% ="))
return false; return false;
@ -265,6 +270,7 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown)
// unknown if it's a dereference // unknown if it's a dereference
unknown = true; unknown = true;
}
// assume that it's not a dereference (no false positives) // assume that it's not a dereference (no false positives)
return false; return false;
@ -355,7 +361,7 @@ void CheckNullPointer::nullPointerAfterLoop()
// loop variable is found.. // loop variable is found..
else if (tok2->varId() == varid) { else if (tok2->varId() == varid) {
// dummy variable.. is it unknown if pointer is dereferenced or not? // dummy variable.. is it unknown if pointer is dereferenced or not?
bool unknown = false; bool unknown = _settings->inconclusive;
// Is the loop variable dereferenced? // Is the loop variable dereferenced?
if (CheckNullPointer::isPointerDeRef(tok2, unknown)) { if (CheckNullPointer::isPointerDeRef(tok2, unknown)) {
@ -921,7 +927,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
// unknown: this is set to true by isPointerDeRef if // unknown: this is set to true by isPointerDeRef if
// the function fails to determine if there // the function fails to determine if there
// is a dereference or not // is a dereference or not
bool unknown = false; bool unknown = _settings->inconclusive;
if (Token::Match(tok2->previous(), "[;{}=] %var% = 0 ;")) if (Token::Match(tok2->previous(), "[;{}=] %var% = 0 ;"))
; ;
@ -1153,7 +1159,7 @@ private:
// unknown : not really used. it is passed to isPointerDeRef. // unknown : not really used. it is passed to isPointerDeRef.
// if isPointerDeRef fails to determine if there // if isPointerDeRef fails to determine if there
// is a dereference the this will be set to true. // is a dereference the this will be set to true.
bool unknown = false; bool unknown = owner->inconclusiveFlag();
if (Token::Match(tok.previous(), "[;{}=] %var% = 0 ;")) if (Token::Match(tok.previous(), "[;{}=] %var% = 0 ;"))
setnull(checks, tok.varId()); setnull(checks, tok.varId());