From 8f50adc7dc60352081a63a1f4ffb6511ddb1f3ec Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sat, 13 Jun 2026 20:57:11 +0200 Subject: [PATCH] Fix #14838 FP invalidLifetime, objectIndex with copy to pointer alias --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 64a48285fdc..68e989c0738 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2591,7 +2591,7 @@ static void valueFlowLifetimeFunction(Token *tok, const TokenList &tokenlist, Er std::vector args = getArguments(tok); if (iArg > 0 && iArg <= args.size()) { const Token* varTok = args[iArg - 1]; - if (varTok->variable() && varTok->variable()->isLocal()) + if (varTok->variable() && varTok->variable()->isLocal() && varTok->variable()->isArray()) LifetimeStore{ varTok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::LifetimeKind::Address }.byRef( tok->next(), tokenlist, errorLogger, settings); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 65f198dcbab..0c8addb3b94 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -908,6 +908,19 @@ class TestValueFlow : public TestFixture { ASSERT_EQUALS(true, lifetimes.size() == 1); ASSERT_EQUALS(true, lifetimes.front() == "a"); } + { + const char code[] = "void f(const char *s, size_t len) {\n" + " char buf[10];\n" + " {\n" + " char *tmp = buf;\n" + " s = strcpy(tmp, s);\n" + " }\n" + " if (s[len] == '\0') {}\n" + "}\n"; + lifetimes = lifetimeValues(code, "s ["); + ASSERT_EQUALS(true, lifetimes.size() == 1); + ASSERT_EQUALS(true, lifetimes.front() == "buf"); + } } void valueFlowArrayElement() {