Fix 11024: FP returnDanglingLifetime with c_str() passed to constructor (#4072)

This commit is contained in:
Paul Fultz II 2022-05-03 04:42:32 -05:00 committed by GitHub
parent 9f7c34272d
commit 3edb10a006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -3888,6 +3888,8 @@ static void valueFlowLifetimeConstructor(Token* tok,
const Token* expr = tok2->astOperand2();
if (!var)
continue;
if (!isLifetimeBorrowed(expr, settings))
continue;
const Variable* argvar = getLifetimeVariable(expr);
if (var->isReference() || var->isRValueReference()) {
if (argvar && argvar->isArgument() && (argvar->isReference() || argvar->isRValueReference())) {

View File

@ -3269,6 +3269,17 @@ private:
"}\n",
true);
ASSERT_EQUALS("", errout.str());
check("struct S {\n"
" std::string msg;\n"
" explicit S(const char* m) : msg(m) {}\n"
"};\n"
"S f() {\n"
" std::string s(\"abc\");\n"
" return S(s.c_str());\n"
"}\n",
true);
ASSERT_EQUALS("", errout.str());
}
void danglingLifetimeAggegrateConstructor() {