From b70a36b9dbda5feb55174f72b40d230e53535e1c Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Thu, 29 Aug 2024 23:11:35 +0200 Subject: [PATCH] Fix #13057 FP: Returning pointer to local variable --- lib/valueflow.cpp | 2 ++ test/testautovariables.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 72da844aa87..8ed603284c5 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3017,6 +3017,8 @@ static void valueFlowLifetimeFunction(Token *tok, const TokenList &tokenlist, Er // TODO: Propagate lifetimes with library functions if (settings.library.getFunction(tok->previous())) return; + if (Token::simpleMatch(tok->astParent(), ".")) + return; // Assume constructing the valueType valueFlowLifetimeConstructor(tok->next(), tokenlist, errorLogger, settings); valueFlowForwardLifetime(tok->next(), tokenlist, errorLogger, settings); diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 58bf423dadd..d9d0e8cb190 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -3504,6 +3504,13 @@ class TestAutoVariables : public TestFixture { " return par;\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("struct S { int* (*ptr)(const int*); };\n" // #13057 + "int* f(S* s) {\n" + " int x = 0;\n" + " return s->ptr(&x);\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void danglingLifetimeUserConstructor()