From 50b9a361b52dfb71366e73b43860286d4fd51ca3 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 15 Sep 2026 13:54:07 +0200 Subject: [PATCH 1/7] Update valueflow.cpp --- lib/valueflow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index aa0b2c91c29..fc464cc925b 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5160,9 +5160,10 @@ static void valueFlowInferCondition(TokenList& tokenlist, const Settings& settin setTokenValue(tok, std::move(value), settings); } } - } else if (Token::Match(tok->astParent(), "?|&&|!|%oror%") || + } else if (Token::Match(tok->astParent(), "&&|!|%oror%") || Token::Match(tok->astParent()->previous(), "if|while (") || - (astIsPointer(tok) && isUsedAsBool(tok, settings))) { + (astIsPointer(tok) && isUsedAsBool(tok, settings)) || + (astIsLHS(tok) && Token::simpleMatch(tok->astParent(), "?"))) { std::vector result = infer(makeIntegralInferModel(), "!=", tok->values(), 0); if (result.size() != 1) continue; From 67eb1594883b4840a611bd1369a0ce399791e474 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 15 Sep 2026 13:55:03 +0200 Subject: [PATCH 2/7] Update vf_settokenvalue.cpp --- lib/vf_settokenvalue.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lib/vf_settokenvalue.cpp b/lib/vf_settokenvalue.cpp index 9f56b57db0a..bd47aa2bdc5 100644 --- a/lib/vf_settokenvalue.cpp +++ b/lib/vf_settokenvalue.cpp @@ -426,22 +426,6 @@ namespace ValueFlow setTokenValue(parent, std::move(value), settings); } } else if (!value.isImpossible()) { - // is condition only depending on 1 variable? - nonneg int varId = 0; - bool ret = false; - visitAstNodes(parent->astOperand1(), - [&](const Token *t) { - if (t->varId()) { - if (varId > 0 || value.varId != 0) - ret = true; - varId = t->varId(); - } else if (t->str() == "(" && Token::Match(t->previous(), "%name%")) - ret = true; // function call - return ret ? ChildrenToVisit::done : ChildrenToVisit::op1_and_op2; - }); - if (ret) - return; - value.conditional = true; value.changeKnownToPossible(); From 86f316ffcc8d31b5e4fa272872c1a2ae09421d4a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 15 Sep 2026 13:57:41 +0200 Subject: [PATCH 3/7] Update testvalueflow.cpp --- test/testvalueflow.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 618e16624d8..4a6952790b8 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -4286,6 +4286,26 @@ class TestValueFlow : public TestFixture { "}\n"; auto values = tokenValues(code, "s :", ValueFlow::Value::ValueType::FLOAT); ASSERT_EQUALS(0, values.size()); + + code = "int a[5];\n" // 15034 + "int g(int i) {\n" + " return a[i < 0 ? -i : i];\n" + "}\n" + "int f() {\n" + " return g(-5);\n" + "}\n"; + values = tokenValues(code, "?"); + ASSERT_EQUALS(2, values.size()); + auto it = values.begin(); + ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueType::INT, it->valueType); + ASSERT_EQUALS(0, it->intvalue); + ASSERT_EQUALS_ENUM(ValueFlow::Value::Bound::Lower, it->bound); + ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueKind::Possible, it->valueKind); + ++it; + ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueType::INT, it->valueType); + ASSERT_EQUALS(5, it->intvalue); + ASSERT_EQUALS_ENUM(ValueFlow::Value::Bound::Point, it->bound); + ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueKind::Possible, it->valueKind); } void valueFlowForwardLambda() { From 55d825007d674ce7fc049083e5aef7696beaea39 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 15 Sep 2026 14:02:35 +0200 Subject: [PATCH 4/7] Update testvalueflow.cpp --- test/testvalueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 4a6952790b8..73f31875b2d 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -4286,7 +4286,7 @@ class TestValueFlow : public TestFixture { "}\n"; auto values = tokenValues(code, "s :", ValueFlow::Value::ValueType::FLOAT); ASSERT_EQUALS(0, values.size()); - + code = "int a[5];\n" // 15034 "int g(int i) {\n" " return a[i < 0 ? -i : i];\n" From 1406a5707e7126df34e24a654a2ea05f3c841c96 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 15 Sep 2026 16:21:46 +0200 Subject: [PATCH 5/7] Update testsymboldatabase.cpp --- test/testsymboldatabase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index dfb61665b8a..675645b6adf 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -3631,7 +3631,7 @@ class TestSymbolDatabase : public TestFixture { ASSERT(fredScope != nullptr); // The struct Fred has two functions, a constructor and a destructor - ASSERT_EQUALS(2U, fredScope->functionList.size()); + ASSERT_EQUALS(2U, fredScope->functionList.size()); // cppcheck-suppress nullPointer // see ticket #9747 // Get linenumbers where the bodies for the constructor and destructor are.. unsigned int constructor = 0; From c9716c633a5b9009ea42863ebbcb790d7f091a90 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 13 Oct 2026 16:18:14 +0200 Subject: [PATCH 6/7] Update testvalueflow.cpp --- test/testvalueflow.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 19515c633d7..6af46e650a8 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -4345,6 +4345,25 @@ class TestValueFlow : public TestFixture { ASSERT_EQUALS(5, it->intvalue); ASSERT_EQUALS_ENUM(ValueFlow::Value::Bound::Point, it->bound); ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueKind::Possible, it->valueKind); + + code = "int f(int a, int b) {\n" + " if (b <= 0)\n" + " return b;\n" + " int a = (a > 0) ? a : -a;\n" + " return 1 / (a < b ? b : a);\n" + "}\n"; + values = tokenValues(code, "? b"); + ASSERT_EQUALS(2, values.size()); + it = values.begin(); + ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueType::SYMBOLIC, it->valueType); + ASSERT_EQUALS(-1, it->intvalue); + ASSERT_EQUALS_ENUM(ValueFlow::Value::Bound::Upper, it->bound); + ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueKind::Impossible, it->valueKind); + ++it; + ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueType::SYMBOLIC, it->valueType); + ASSERT_EQUALS(-1, it->intvalue); + ASSERT_EQUALS_ENUM(ValueFlow::Value::Bound::Upper, it->bound); + ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueKind::Impossible, it->valueKind); } void valueFlowForwardLambda() { From dff62149e0923ed9adeb269a475b6de6d54d607c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 13 Oct 2026 16:20:50 +0200 Subject: [PATCH 7/7] Update vf_settokenvalue.cpp --- lib/vf_settokenvalue.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/vf_settokenvalue.cpp b/lib/vf_settokenvalue.cpp index 11a17b3c6a4..5c88a9bd763 100644 --- a/lib/vf_settokenvalue.cpp +++ b/lib/vf_settokenvalue.cpp @@ -428,6 +428,21 @@ namespace ValueFlow setTokenValue(parent, std::move(value), settings); } } else if (!value.isImpossible()) { + // is condition only depending on 1 variable? + nonneg int varId = 0; + bool ret = false; + visitAstNodes(parent->astOperand1(), + [&](const Token *t) { + if (t->varId()) { + if (varId > 0) + ret = true; + varId = t->varId(); + } else if (t->str() == "(" && Token::Match(t->previous(), "%name%")) + ret = true; // function call + return ret ? ChildrenToVisit::done : ChildrenToVisit::op1_and_op2; + }); + if (ret) + return; value.conditional = true; value.changeKnownToPossible();