From fba5307c03dfb82a16acff1c5fe9a660ef827f24 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sun, 25 Aug 2024 00:08:06 +0200 Subject: [PATCH] Fix #12727 FP knownConditionTrueFalse (wrong range of return values) --- 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 dab952aa9a3..c8792a766d6 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -579,7 +579,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 db044308c71..d46a016072f 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4988,6 +4988,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() {