Fix related to previously fixed #3256 (Null pointer dereference not detected)
Use reportInconclusiveError() instead of reportError().
This commit is contained in:
parent
a79b5a5c36
commit
12a10a7297
|
@ -768,6 +768,9 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
||||||
// Name of the pointer
|
// Name of the pointer
|
||||||
const std::string &pointerName = vartok->str();
|
const std::string &pointerName = vartok->str();
|
||||||
|
|
||||||
|
// Set to true if we would normally bail out the check.
|
||||||
|
bool inconclusive = false;
|
||||||
|
|
||||||
// Count { and } for tok2
|
// Count { and } for tok2
|
||||||
for (const Token *tok2 = tok1; tok2; tok2 = tok2->next()) {
|
for (const Token *tok2 = tok1; tok2; tok2 = tok2->next()) {
|
||||||
if (tok2->str() == "{")
|
if (tok2->str() == "{")
|
||||||
|
@ -788,10 +791,10 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
||||||
if (Token::Match(tok2, "goto|return|continue|break|throw|if|switch")) {
|
if (Token::Match(tok2, "goto|return|continue|break|throw|if|switch")) {
|
||||||
bool dummy = false;
|
bool dummy = false;
|
||||||
if (Token::Match(tok2, "return * %varid%", varid))
|
if (Token::Match(tok2, "return * %varid%", varid))
|
||||||
nullPointerError(tok2, pointerName, linenr);
|
nullPointerError(tok2, pointerName, linenr, inconclusive);
|
||||||
else if (Token::Match(tok2, "return %varid%", varid) &&
|
else if (Token::Match(tok2, "return %varid%", varid) &&
|
||||||
CheckNullPointer::isPointerDeRef(tok2->next(), dummy))
|
CheckNullPointer::isPointerDeRef(tok2->next(), dummy))
|
||||||
nullPointerError(tok2, pointerName, linenr);
|
nullPointerError(tok2, pointerName, linenr, inconclusive);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -807,7 +810,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
||||||
parseFunctionCall(*tok2, var, 0);
|
parseFunctionCall(*tok2, var, 0);
|
||||||
for (std::list<const Token *>::const_iterator it = var.begin(); it != var.end(); ++it) {
|
for (std::list<const Token *>::const_iterator it = var.begin(); it != var.end(); ++it) {
|
||||||
if ((*it)->varId() == varid) {
|
if ((*it)->varId() == varid) {
|
||||||
nullPointerError(*it, pointerName, linenr);
|
nullPointerError(*it, pointerName, linenr, inconclusive);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -817,13 +820,15 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
||||||
if (Token::simpleMatch(tok2, ") ;") &&
|
if (Token::simpleMatch(tok2, ") ;") &&
|
||||||
(Token::Match(tok2->link()->tokAt(-2), "[;{}.] %var% (") ||
|
(Token::Match(tok2->link()->tokAt(-2), "[;{}.] %var% (") ||
|
||||||
Token::Match(tok2->link()->tokAt(-5), "[;{}] ( * %var% ) ("))) {
|
Token::Match(tok2->link()->tokAt(-5), "[;{}] ( * %var% ) ("))) {
|
||||||
if (!_settings->inconclusive) {
|
// noreturn function?
|
||||||
// noreturn function?
|
// If inside null pointer check we unknown function call, we must
|
||||||
// If inside null pointer check we unknown function call, we must
|
// assume that it can terminate the program and possible null pointer
|
||||||
// assume that it can terminate the program and possible null pointer
|
// error wont ever happen.
|
||||||
// error wont ever happen.
|
if (tok2->strAt(2) == "}") {
|
||||||
if (tok2->strAt(2) == "}")
|
if (!_settings->inconclusive) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
inconclusive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// init function (global variables)
|
// init function (global variables)
|
||||||
|
@ -843,7 +848,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
||||||
;
|
;
|
||||||
|
|
||||||
else if (CheckNullPointer::isPointerDeRef(tok2, unknown))
|
else if (CheckNullPointer::isPointerDeRef(tok2, unknown))
|
||||||
nullPointerError(tok2, pointerName, linenr);
|
nullPointerError(tok2, pointerName, linenr, inconclusive);
|
||||||
|
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue