From 7e929f864b6ded3c97bb701f72c0d3541b8f49b8 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Wed, 17 Jun 2026 21:42:45 +0200 Subject: [PATCH 1/3] Fix #14848 FP compareValueOutOfTypeRangeError and knownConditionTrueFalse with unsigned arithmetic --- lib/vf_settokenvalue.cpp | 2 +- test/testvalueflow.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/vf_settokenvalue.cpp b/lib/vf_settokenvalue.cpp index fe94225083b..315f4a40129 100644 --- a/lib/vf_settokenvalue.cpp +++ b/lib/vf_settokenvalue.cpp @@ -613,7 +613,7 @@ namespace ValueFlow } // unary minus - else if (parent->isUnaryOp("-")) { + else if (parent->isUnaryOp("-") && !astIsUnsigned(parent)) { for (const Value &val : tok->values()) { if (!val.isIntValue() && !val.isFloatValue()) continue; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 0c8addb3b94..84396ac14e1 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1261,6 +1261,12 @@ class TestValueFlow : public TestFixture { ASSERT_EQUALS(1U, values.size()); ASSERT_EQUALS(-10, values.back().intvalue); + code = "bool f(unsigned a) {\n" + " bool x = -a < 1;\n" + " return x;\n" + "}"; + ASSERT_EQUALS(false, testValueOfXKnown(code, 3U, 1)); + // Logical and code = "void f(bool b) {\n" " bool x = false && b;\n" From 4607f96bec834e03d8e6337c4b5f16095492e5a5 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Wed, 17 Jun 2026 21:49:36 +0200 Subject: [PATCH 2/3] Format --- test/testvalueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 84396ac14e1..e5dc1a6e96c 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1264,7 +1264,7 @@ class TestValueFlow : public TestFixture { code = "bool f(unsigned a) {\n" " bool x = -a < 1;\n" " return x;\n" - "}"; + "}"; ASSERT_EQUALS(false, testValueOfXKnown(code, 3U, 1)); // Logical and From 79b2132729def2339aa08e90f0940141542a8118 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 18 Jun 2026 07:19:13 +0200 Subject: [PATCH 3/3] Update testvalueflow.cpp [skip ci] --- test/testvalueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index e5dc1a6e96c..6a1ebe9d95e 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1261,7 +1261,7 @@ class TestValueFlow : public TestFixture { ASSERT_EQUALS(1U, values.size()); ASSERT_EQUALS(-10, values.back().intvalue); - code = "bool f(unsigned a) {\n" + code = "bool f(unsigned a) {\n" // #14848 " bool x = -a < 1;\n" " return x;\n" "}";