diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index d12a049ce..c6fb727bf 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -762,18 +762,42 @@ void CheckNullPointer::nullPointerByDeRefAndChec() if (!var || !var->isPointer()) continue; + const ValueFlow::Value *value = 0; + for (std::list::const_iterator it = tok->values.begin(); it != tok->values.end(); ++it) { + if (it->intvalue == 0) { + value = &(*it); + break; + } + } + if (!value) + continue; + + if (Token::Match(tok->previous(), "[(,] %var% [,)]")) { + const Token *ftok = tok->previous(); + while (ftok && ftok->str() != "(") { + if (ftok->str() == ")") + ftok = ftok->link(); + ftok = ftok->previous(); + } + std::list varlist; + parseFunctionCall(*ftok->previous(), varlist, &_settings->library, 0); + if (std::find(varlist.begin(), varlist.end(), tok) != varlist.end()) { + if (value->condition == NULL) + nullPointerError(tok); + else if (_settings->isEnabled("warning")) + nullPointerError(tok, tok->str(), value->condition, false); + } + continue; + } + bool unknown = false; if (!isPointerDeRef(tok,unknown)) continue; - for (std::list::const_iterator it = tok->values.begin(); it != tok->values.end(); ++it) { - if (it->intvalue != 0) - continue; - if (it->condition == NULL) - nullPointerError(tok); - else if (_settings->isEnabled("warning")) - nullPointerError(tok, tok->str(), it->condition, false); - } + if (value->condition == NULL) + nullPointerError(tok); + else if (_settings->isEnabled("warning")) + nullPointerError(tok, tok->str(), value->condition, false); } return; } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index ab7e30032..cd245385f 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -88,6 +88,13 @@ private: settings.inconclusive = inconclusive; //settings.valueFlow = true; + // cfg + const char cfg[] = "\n" + "\n" + " \n" + ""; + settings.library.loadxmldata(cfg, sizeof(cfg)); + // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code);