diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 36dbb1c88..656cbb5a7 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -768,6 +768,9 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() // Name of the pointer const std::string &pointerName = vartok->str(); + // Set to true if we would normally bail out the check. + bool inconclusive = false; + // Count { and } for tok2 for (const Token *tok2 = tok1; tok2; tok2 = tok2->next()) { if (tok2->str() == "{") @@ -788,10 +791,10 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() if (Token::Match(tok2, "goto|return|continue|break|throw|if|switch")) { bool dummy = false; if (Token::Match(tok2, "return * %varid%", varid)) - nullPointerError(tok2, pointerName, linenr); + nullPointerError(tok2, pointerName, linenr, inconclusive); else if (Token::Match(tok2, "return %varid%", varid) && CheckNullPointer::isPointerDeRef(tok2->next(), dummy)) - nullPointerError(tok2, pointerName, linenr); + nullPointerError(tok2, pointerName, linenr, inconclusive); break; } @@ -807,7 +810,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() parseFunctionCall(*tok2, var, 0); for (std::list::const_iterator it = var.begin(); it != var.end(); ++it) { if ((*it)->varId() == varid) { - nullPointerError(*it, pointerName, linenr); + nullPointerError(*it, pointerName, linenr, inconclusive); break; } } @@ -817,13 +820,15 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() if (Token::simpleMatch(tok2, ") ;") && (Token::Match(tok2->link()->tokAt(-2), "[;{}.] %var% (") || Token::Match(tok2->link()->tokAt(-5), "[;{}] ( * %var% ) ("))) { - if (!_settings->inconclusive) { - // noreturn function? - // If inside null pointer check we unknown function call, we must - // assume that it can terminate the program and possible null pointer - // error wont ever happen. - if (tok2->strAt(2) == "}") + // noreturn function? + // If inside null pointer check we unknown function call, we must + // assume that it can terminate the program and possible null pointer + // error wont ever happen. + if (tok2->strAt(2) == "}") { + if (!_settings->inconclusive) { break; + } + inconclusive = true; } // init function (global variables) @@ -843,7 +848,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() ; else if (CheckNullPointer::isPointerDeRef(tok2, unknown)) - nullPointerError(tok2, pointerName, linenr); + nullPointerError(tok2, pointerName, linenr, inconclusive); else break;