Fix 10308: danglingTemporaryLifetime confused by function parameter (#3292)

This commit is contained in:
Paul Fultz II 2021-06-09 02:21:03 -05:00 committed by GitHub
parent f3a33ea330
commit f55a4563f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -570,7 +570,7 @@ static void setTokenValue(Token* tok, ValueFlow::Value value, const Settings* se
if (value.lifetimeKind == ValueFlow::Value::LifetimeKind::Iterator && astIsIterator(parent)) {
setTokenValue(parent,value,settings);
} else if (astIsPointer(tok) && astIsPointer(parent) &&
(parent->isArithmeticalOp() || Token::Match(parent, "( %type%"))) {
(parent->isArithmeticalOp() || parent->isCast())) {
setTokenValue(parent,value,settings);
}
return;

View File

@ -2927,6 +2927,19 @@ private:
" return state;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("struct var {\n"
" void fun();\n"
"}x;\n"
"var* T(const char*) {\n"
" return &x;\n"
"}\n"
"std::string GetTemp();\n"
"void f() {\n"
" auto a = T(GetTemp().c_str());\n"
" a->fun();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void invalidLifetime() {