Skip to content

Commit

Permalink
Fix #13057 FP: Returning pointer to local variable
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Aug 29, 2024
1 parent 4ba0767 commit b70a36b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b70a36b

Please sign in to comment.