From e8d37ed6af81ce22c84efb30a049f9a94b77a998 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 10 Oct 2025 23:07:57 +0200 Subject: [PATCH 1/5] Fix #14191 FP uninitvar with conditional pointer reassignment --- lib/vf_analyzers.cpp | 2 ++ test/testuninitvar.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/vf_analyzers.cpp b/lib/vf_analyzers.cpp index 1b70b4446d1..fc64f237c39 100644 --- a/lib/vf_analyzers.cpp +++ b/lib/vf_analyzers.cpp @@ -608,6 +608,8 @@ struct ValueFlowAnalyzer : Analyzer { for (const ValueFlow::Value& v:ref->astOperand1()->values()) { if (!v.isLocalLifetimeValue()) continue; + if (v.conditional) + continue; if (lifeTok) return Action::None; lifeTok = v.tokvalue; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 9652bbc5e59..051649ac77a 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -7936,6 +7936,20 @@ class TestUninitVar : public TestFixture { " return s;\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + valueFlowUninit("struct S { int i; };\n" // #14191 + "bool g(S*);\n" + "void f( struct S *p) {\n" + " struct S s;\n" + " if (!p) {\n" + " p = &s;\n" + " if (g(p))\n" + " return;\n" + " }\n" + " printf(\"%i\", p->i);\n" + " p = &s;\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } template From 090b7e8708cd64e0735f5f1be4d60c56ea6ac39d Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sun, 12 Oct 2025 23:15:13 +0200 Subject: [PATCH 2/5] Fix #14193 FP knownConditionTrueFalse for loop references to container elements --- lib/astutils.cpp | 2 ++ test/testother.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index f55164f62fa..d01dcdc3616 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1203,6 +1203,8 @@ static const Token * followVariableExpression(const Settings& settings, const To return tok; if (hasUnknownVars(varTok)) return tok; + //if (astIsRangeBasedForDecl(var->nameToken())) + // return tok; if (var->isVolatile()) return tok; if (!var->isLocal() && !var->isConst()) diff --git a/test/testother.cpp b/test/testother.cpp index c9be6eeb319..b716e114434 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -8004,6 +8004,15 @@ class TestOther : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("void f(const std::vector& v) {\n" + " for (const int& r1 : v) {\n" + " for (const int& r2 : v) {\n" + " if (&r1 == &r2) {}\n" + " }\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void duplicateExpressionTernary() { // #6391 From 174c29c3d83fd6db7b866f7cef50d1a50d42f68d Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sun, 12 Oct 2025 23:17:04 +0200 Subject: [PATCH 3/5] Fix --- lib/astutils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index d01dcdc3616..8c9b81f1e8d 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1203,8 +1203,8 @@ static const Token * followVariableExpression(const Settings& settings, const To return tok; if (hasUnknownVars(varTok)) return tok; - //if (astIsRangeBasedForDecl(var->nameToken())) - // return tok; + if (astIsRangeBasedForDecl(var->nameToken())) + return tok; if (var->isVolatile()) return tok; if (!var->isLocal() && !var->isConst()) From a06b8555f7e194b2bbe2bb022b355ce9a568d814 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 13 Oct 2025 08:29:15 +0200 Subject: [PATCH 4/5] Update testother.cpp --- test/testother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testother.cpp b/test/testother.cpp index 9eefc14ea6e..8c8966b272d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -8027,7 +8027,7 @@ class TestOther : public TestFixture { " for (const int& r2 : v) {\n" " if (&r1 == &r2) {}\n" " }\n" - " }\n" + " }\n" "}\n"); ASSERT_EQUALS("", errout_str()); } From e7e85b46fb5e0499ff41ab87472449d3c4e69ef4 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 13 Oct 2025 08:30:32 +0200 Subject: [PATCH 5/5] Update testother.cpp --- test/testother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testother.cpp b/test/testother.cpp index 8c8966b272d..6398cd37cbb 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -8022,7 +8022,7 @@ class TestOther : public TestFixture { "}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(const std::vector& v) {\n" + check("void f(const std::vector& v) {\n" // #14193 " for (const int& r1 : v) {\n" " for (const int& r2 : v) {\n" " if (&r1 == &r2) {}\n"