From f55a4563f9f6aabad9c157efed4bd7abcf96b154 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Wed, 9 Jun 2021 02:21:03 -0500 Subject: [PATCH] Fix 10308: danglingTemporaryLifetime confused by function parameter (#3292) --- lib/valueflow.cpp | 2 +- test/testautovariables.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index a030f5cbd..2b1f1d831 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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; diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 16ec345a3..ad4598d94 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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() {