From 04f7a9b4c75bbcaa584f6c4656c11dae1a470882 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 25 Aug 2024 22:21:47 +0200 Subject: [PATCH] Fix #12727 FP knownConditionTrueFalse (wrong range of return values) (#6721) --- lib/programmemory.cpp | 1 - test/testcondition.cpp | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index ee52f003b5d..97c1756a4c0 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -602,7 +602,6 @@ static bool isIntegralValue(const ValueFlow::Value& value) static ValueFlow::Value evaluate(const std::string& op, const ValueFlow::Value& lhs, const ValueFlow::Value& rhs) { ValueFlow::Value result; - combineValueProperties(lhs, rhs, result); if (lhs.isImpossible() && rhs.isImpossible()) return ValueFlow::Value::unknown(); if (lhs.isImpossible() || rhs.isImpossible()) { diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 45ec8d5fb24..4f419146685 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -5108,6 +5108,22 @@ class TestCondition : public TestFixture { " if ((128 + i < 255 ? 128 + i : 255) > 0) {}\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("struct S {\n" // #12727 + " bool f() const {\n" + " return g() > 0;\n" + " }\n" + " std::size_t g() const {\n" + " return 5 - h();\n" + " }\n" + " std::size_t h() const {\n" + " if (x > 7)\n" + " return 5;\n" + " return (5 + x) % 5;\n" + " }\n" + " std::size_t x;\n" + "};\n"); + ASSERT_EQUALS("", errout_str()); } void alwaysTrueContainer() {