@@ -762,18 +762,42 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
762762 if (!var || !var->isPointer ())
763763 continue ;
764764
765+ const ValueFlow::Value *value = 0 ;
766+ for (std::list<ValueFlow::Value>::const_iterator it = tok->values .begin (); it != tok->values .end (); ++it) {
767+ if (it->intvalue == 0 ) {
768+ value = &(*it);
769+ break ;
770+ }
771+ }
772+ if (!value)
773+ continue ;
774+
775+ if (Token::Match (tok->previous (), " [(,] %var% [,)]" )) {
776+ const Token *ftok = tok->previous ();
777+ while (ftok && ftok->str () != " (" ) {
778+ if (ftok->str () == " )" )
779+ ftok = ftok->link ();
780+ ftok = ftok->previous ();
781+ }
782+ std::list<const Token *> varlist;
783+ parseFunctionCall (*ftok->previous (), varlist, &_settings->library , 0 );
784+ if (std::find (varlist.begin (), varlist.end (), tok) != varlist.end ()) {
785+ if (value->condition == NULL )
786+ nullPointerError (tok);
787+ else if (_settings->isEnabled (" warning" ))
788+ nullPointerError (tok, tok->str (), value->condition , false );
789+ }
790+ continue ;
791+ }
792+
765793 bool unknown = false ;
766794 if (!isPointerDeRef (tok,unknown))
767795 continue ;
768796
769- for (std::list<ValueFlow::Value>::const_iterator it = tok->values .begin (); it != tok->values .end (); ++it) {
770- if (it->intvalue != 0 )
771- continue ;
772- if (it->condition == NULL )
773- nullPointerError (tok);
774- else if (_settings->isEnabled (" warning" ))
775- nullPointerError (tok, tok->str (), it->condition , false );
776- }
797+ if (value->condition == NULL )
798+ nullPointerError (tok);
799+ else if (_settings->isEnabled (" warning" ))
800+ nullPointerError (tok, tok->str (), value->condition , false );
777801 }
778802 return ;
779803 }
0 commit comments