@@ -645,14 +645,14 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
645645 const Token* nextTok = nextAfterAstRightmostLeaf (tok->astTop ());
646646 if (!nextTok)
647647 nextTok = tok->next ();
648- if (var && !var->isLocal () && !var->isArgument () && !(val.tokvalue && val.tokvalue ->variable () && val.tokvalue ->variable ()->isStatic ()) &&
648+ if (var && ( !var->isLocal () || var-> isStatic () ) && !var->isArgument () && !(val.tokvalue && val.tokvalue ->variable () && val.tokvalue ->variable ()->isStatic ()) &&
649649 !isVariableChanged (nextTok,
650650 tok->scope ()->bodyEnd ,
651651 var->valueType () ? var->valueType ()->pointer : 0 ,
652652 var->declarationId (),
653653 var->isGlobal (),
654654 *mSettings )) {
655- errorDanglngLifetime (tok2, &val);
655+ errorDanglngLifetime (tok2, &val, var-> isLocal () );
656656 break ;
657657 }
658658 }
@@ -722,12 +722,13 @@ void CheckAutoVariables::errorDanglingTemporaryLifetime(const Token* tok, const
722722 inconclusive ? Certainty::inconclusive : Certainty::normal);
723723}
724724
725- void CheckAutoVariables::errorDanglngLifetime (const Token *tok, const ValueFlow::Value *val)
725+ void CheckAutoVariables::errorDanglngLifetime (const Token *tok, const ValueFlow::Value *val, bool isStatic )
726726{
727727 const bool inconclusive = val ? val->isInconclusive () : false ;
728728 ErrorPath errorPath = val ? val->errorPath : ErrorPath ();
729729 std::string tokName = tok ? tok->expressionString () : " x" ;
730- std::string msg = " Non-local variable '" + tokName + " ' will use " + lifetimeMessage (tok, val, errorPath);
730+ std::string msg = isStatic ? " Static" : " Non-local" ;
731+ msg += " variable '" + tokName + " ' will use " + lifetimeMessage (tok, val, errorPath);
731732 errorPath.emplace_back (tok, " " );
732733 reportError (errorPath, Severity::error, " danglingLifetime" , msg + " ." , CWE562, inconclusive ? Certainty::inconclusive : Certainty::normal);
733734}
0 commit comments