Skip to content

Commit 94e9a72

Browse files
Fix #13057 FP: Returning pointer to local variable (danmar#6739)
1 parent 56ff2cc commit 94e9a72

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/valueflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,6 +3017,8 @@ static void valueFlowLifetimeFunction(Token *tok, const TokenList &tokenlist, Er
30173017
// TODO: Propagate lifetimes with library functions
30183018
if (settings.library.getFunction(tok->previous()))
30193019
return;
3020+
if (Token::simpleMatch(tok->astParent(), "."))
3021+
return;
30203022
// Assume constructing the valueType
30213023
valueFlowLifetimeConstructor(tok->next(), tokenlist, errorLogger, settings);
30223024
valueFlowForwardLifetime(tok->next(), tokenlist, errorLogger, settings);

test/testautovariables.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3504,6 +3504,13 @@ class TestAutoVariables : public TestFixture {
35043504
" return par;\n"
35053505
"}\n");
35063506
ASSERT_EQUALS("", errout_str());
3507+
3508+
check("struct S { int* (*ptr)(const int*); };\n" // #13057
3509+
"int* f(S* s) {\n"
3510+
" int x = 0;\n"
3511+
" return s->ptr(&x);\n"
3512+
"}\n");
3513+
ASSERT_EQUALS("", errout_str());
35073514
}
35083515

35093516
void danglingLifetimeUserConstructor()

0 commit comments

Comments
 (0)