@@ -31,6 +31,11 @@ namespace {
3131
3232// ---------------------------------------------------------------------------
3333
34+ static bool checkNullpointerFunctionCallPlausibility (const Function* func, unsigned int arg)
35+ {
36+ return !func || (func->argCount () >= arg && func->getArgumentVar (arg - 1 ) && func->getArgumentVar (arg - 1 )->isPointer ());
37+ }
38+
3439/* *
3540 * @brief parse a function call and extract information about variable usage
3641 * @param tok first token
@@ -52,17 +57,17 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
5257 (value == 0 && Token::Match (firstParam, " 0|NULL ,|)" ))) {
5358 if (value == 0 && Token::Match (&tok, " snprintf|vsnprintf|fnprintf|vfnprintf" ) && secondParam && secondParam->str () != " 0" ) // Only if length (second parameter) is not zero
5459 var.push_back (firstParam);
55- else if (value == 0 && library != nullptr && library->isnullargbad (tok.str (),1 ))
60+ else if (value == 0 && library != nullptr && library->isnullargbad (tok.str (), 1 ) && checkNullpointerFunctionCallPlausibility (tok. function (), 1 ))
5661 var.push_back (firstParam);
57- else if (value == 1 && library != nullptr && library->isuninitargbad (tok.str (),1 ))
62+ else if (value == 1 && library != nullptr && library->isuninitargbad (tok.str (), 1 ))
5863 var.push_back (firstParam);
5964 }
6065
6166 // 2nd parameter..
6267 if ((value == 0 && Token::Match (secondParam, " 0|NULL ,|)" )) || (secondParam && secondParam->varId () > 0 && Token::Match (secondParam->next ()," [,)]" ))) {
63- if (value == 0 && library != nullptr && library->isnullargbad (tok.str (),2 ))
68+ if (value == 0 && library != nullptr && library->isnullargbad (tok.str (), 2 ) && checkNullpointerFunctionCallPlausibility (tok. function (), 2 ))
6469 var.push_back (secondParam);
65- else if (value == 1 && library != nullptr && library->isuninitargbad (tok.str (),2 ))
70+ else if (value == 1 && library != nullptr && library->isuninitargbad (tok.str (), 2 ))
6671 var.push_back (secondParam);
6772 }
6873
0 commit comments