@@ -442,6 +442,8 @@ void CheckNullPointer::nullPointerError(const Token *tok, const std::string &var
442442 reportError (tok, Severity::error, " nullPointer" , " Null pointer dereference" , CWE_NULL_POINTER_DEREFERENCE, Certainty::normal);
443443 reportError (tok, Severity::warning, " nullPointerDefaultArg" , errmsgdefarg, CWE_NULL_POINTER_DEREFERENCE, Certainty::normal);
444444 reportError (tok, Severity::warning, " nullPointerRedundantCheck" , errmsgcond, CWE_NULL_POINTER_DEREFERENCE, Certainty::normal);
445+ reportError (tok, Severity::warning, " nullPointerOutOfMemory" , " Null pointer dereference" , CWE_NULL_POINTER_DEREFERENCE, Certainty::normal);
446+ reportError (tok, Severity::warning, " nullPointerOutOfResources" , " Null pointer dereference" , CWE_NULL_POINTER_DEREFERENCE, Certainty::normal);
445447 return ;
446448 }
447449
@@ -461,12 +463,29 @@ void CheckNullPointer::nullPointerError(const Token *tok, const std::string &var
461463 reportError (errorPath, Severity::warning, " nullPointerDefaultArg" , errmsgdefarg, CWE_NULL_POINTER_DEREFERENCE, inconclusive || value->isInconclusive () ? Certainty::inconclusive : Certainty::normal);
462464 } else {
463465 std::string errmsg = std::string (value->isKnown () ? " Null" : " Possible null" ) + " pointer dereference" ;
466+
467+ std::string id = " nullPointer" ;
468+ if (value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfMemory) {
469+ if (errmsg.compare (0 , 9 , " Possible " ) == 0 )
470+ errmsg = " If memory allocation fail: " + errmsg.substr (9 );
471+ else
472+ errmsg = " If memory allocation fail: " + errmsg;
473+ id += " OutOfMemory" ;
474+ }
475+ else if (value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfResources) {
476+ if (errmsg.compare (0 , 9 , " Possible " ) == 0 )
477+ errmsg = " If resource allocation fail: " + errmsg.substr (9 );
478+ else
479+ errmsg = " If resource allocation fail: " + errmsg;
480+ id += " OutOfResources" ;
481+ }
482+
464483 if (!varname.empty ())
465484 errmsg = " $symbol:" + varname + ' \n ' + errmsg + " : $symbol" ;
466485
467486 reportError (errorPath,
468487 value->isKnown () ? Severity::error : Severity::warning,
469- " nullPointer " ,
488+ id. c_str () ,
470489 errmsg,
471490 CWE_NULL_POINTER_DEREFERENCE, inconclusive || value->isInconclusive () ? Certainty::inconclusive : Certainty::normal);
472491 }
@@ -529,10 +548,21 @@ void CheckNullPointer::pointerArithmeticError(const Token* tok, const ValueFlow:
529548 } else {
530549 errmsg = " Pointer " + arithmetic + " with NULL pointer." ;
531550 }
551+
552+ std::string id = " nullPointerArithmetic" ;
553+ if (value && value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfMemory) {
554+ errmsg = " If memory allocation fail: " + ((char )std::tolower (errmsg[0 ]) + errmsg.substr (1 ));
555+ id += " OutOfMemory" ;
556+ }
557+ else if (value && value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfResources) {
558+ errmsg = " If resource allocation fail: " + ((char )std::tolower (errmsg[0 ]) + errmsg.substr (1 ));
559+ id += " OutOfResources" ;
560+ }
561+
532562 const ErrorPath errorPath = getErrorPath (tok, value, " Null pointer " + arithmetic);
533563 reportError (errorPath,
534564 Severity::error,
535- " nullPointerArithmetic " ,
565+ id. c_str () ,
536566 errmsg,
537567 CWE_INCORRECT_CALCULATION,
538568 inconclusive ? Certainty::inconclusive : Certainty::normal);
0 commit comments