From 1dfd306393b04f02cbef5d92a0a79a0c87a11b6b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 15 Oct 2025 09:54:20 +0200 Subject: [PATCH 1/5] Update valueflow.cpp --- lib/valueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 1f725673874..dcd88f10c4d 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1796,7 +1796,7 @@ static std::vector getLifetimeTokens(const Token* tok, if (Token::Match(tok->tokAt(-2), ". %name% (") && tok->tokAt(-2)->originalName() != "->" && astIsContainer(tok->tokAt(-2)->astOperand1())) { const Library::Container* library = getLibraryContainer(tok->tokAt(-2)->astOperand1()); const Library::Container::Yield y = library->getYield(tok->strAt(-1)); - if (y == Library::Container::Yield::AT_INDEX || y == Library::Container::Yield::ITEM) { + if (y == Library::Container::Yield::AT_INDEX || y == Library::Container::Yield::ITEM || y == Library::Container::Yield::BUFFER || y == Library::Container::Yield::BUFFER_NT) { errorPath.emplace_back(tok->previous(), "Accessing container."); return ValueFlow::LifetimeToken::setAddressOf( getLifetimeTokens(tok->tokAt(-2)->astOperand1(), escape, std::move(errorPath), pred, settings, depth - 1), From 9714db605ca02ad440b5ef5d5800ce0c7f775573 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 15 Oct 2025 09:56:43 +0200 Subject: [PATCH 2/5] Update testother.cpp --- test/testother.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index e363642684d..44d4bb3cd4b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3960,6 +3960,9 @@ class TestOther : public TestFixture { check("void push(V& v) { v.push_back({ .x = 1 }); }"); // #14010 ASSERT_EQUALS("", errout_str()); + + check("size_t* f(std::array& a) { return reinterpret_cast(a.data()); }\n"); // #14074 + ASSERT_EQUALS("", errout_str()); } void constParameterCallback() { From 63feadec60333c51884d9b546025fc8498bae58d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 15 Oct 2025 10:00:20 +0200 Subject: [PATCH 3/5] Update valueflow.cpp --- lib/valueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index dcd88f10c4d..764ecd1a5d8 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1796,7 +1796,7 @@ static std::vector getLifetimeTokens(const Token* tok, if (Token::Match(tok->tokAt(-2), ". %name% (") && tok->tokAt(-2)->originalName() != "->" && astIsContainer(tok->tokAt(-2)->astOperand1())) { const Library::Container* library = getLibraryContainer(tok->tokAt(-2)->astOperand1()); const Library::Container::Yield y = library->getYield(tok->strAt(-1)); - if (y == Library::Container::Yield::AT_INDEX || y == Library::Container::Yield::ITEM || y == Library::Container::Yield::BUFFER || y == Library::Container::Yield::BUFFER_NT) { + if (contains({Library::Container::Yield::AT_INDEX, Library::Container::Yield::ITEM, Library::Container::Yield::BUFFER, Library::Container::Yield::BUFFER_NT}, y)) { errorPath.emplace_back(tok->previous(), "Accessing container."); return ValueFlow::LifetimeToken::setAddressOf( getLifetimeTokens(tok->tokAt(-2)->astOperand1(), escape, std::move(errorPath), pred, settings, depth - 1), From 4ff7d316bcd76cc49e5d52e87aa122cba3903817 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 15 Oct 2025 15:56:22 +0200 Subject: [PATCH 4/5] Update checkstl.cpp --- lib/checkstl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index a88591a904a..f2605da8265 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1091,7 +1091,7 @@ static const ValueFlow::Value* getInnerLifetime(const Token* tok, if (!tok) return nullptr; for (const ValueFlow::Value& val : tok->values()) { - if (!val.isLocalLifetimeValue()) + if (!val.isLocalLifetimeValue() && !val.isArgumentLifetimeValue()) continue; if (contains({ValueFlow::Value::LifetimeKind::Address, ValueFlow::Value::LifetimeKind::SubObject, From 53bf05963f0a82af216f12d3eb2ebd46eaca2b33 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Tue, 28 Oct 2025 19:19:52 +0100 Subject: [PATCH 5/5] Fix --- lib/checkother.cpp | 3 +++ lib/checkstl.cpp | 2 +- lib/valueflow.cpp | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index f52b7cf8ba0..7c7cf189323 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1727,6 +1727,9 @@ void CheckOther::checkConstVariable() retTok = retTok->astOperand2(); if (Token::simpleMatch(retTok, "&")) retTok = retTok->astOperand1(); + ValueFlow::Value ltVal = ValueFlow::getLifetimeObjValue(retTok); + if (ltVal.isLifetimeValue() && ltVal.tokvalue->varId() == var->declarationId()) + return true; return ValueFlow::hasLifetimeToken(getParentLifetime(retTok), var->nameToken(), *mSettings); })) continue; diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index f2605da8265..a88591a904a 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1091,7 +1091,7 @@ static const ValueFlow::Value* getInnerLifetime(const Token* tok, if (!tok) return nullptr; for (const ValueFlow::Value& val : tok->values()) { - if (!val.isLocalLifetimeValue() && !val.isArgumentLifetimeValue()) + if (!val.isLocalLifetimeValue()) continue; if (contains({ValueFlow::Value::LifetimeKind::Address, ValueFlow::Value::LifetimeKind::SubObject, diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 764ecd1a5d8..1f725673874 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1796,7 +1796,7 @@ static std::vector getLifetimeTokens(const Token* tok, if (Token::Match(tok->tokAt(-2), ". %name% (") && tok->tokAt(-2)->originalName() != "->" && astIsContainer(tok->tokAt(-2)->astOperand1())) { const Library::Container* library = getLibraryContainer(tok->tokAt(-2)->astOperand1()); const Library::Container::Yield y = library->getYield(tok->strAt(-1)); - if (contains({Library::Container::Yield::AT_INDEX, Library::Container::Yield::ITEM, Library::Container::Yield::BUFFER, Library::Container::Yield::BUFFER_NT}, y)) { + if (y == Library::Container::Yield::AT_INDEX || y == Library::Container::Yield::ITEM) { errorPath.emplace_back(tok->previous(), "Accessing container."); return ValueFlow::LifetimeToken::setAddressOf( getLifetimeTokens(tok->tokAt(-2)->astOperand1(), escape, std::move(errorPath), pred, settings, depth - 1),