From 4e7125554fc8c1d2860bd3c08b5ac2455882d079 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 30 Apr 2022 02:35:51 -0500 Subject: [PATCH] Fix 8358: FP: Condition '(number*0)!=0' is always false (#4065) --- lib/valueflow.cpp | 3 ++- test/testcondition.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index fd6f1c5aa..80c28a503 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -756,7 +756,8 @@ static void setTokenValue(Token* tok, ValueFlow::Value value, const Settings* se return; // known result when a operand is 0. - if (Token::Match(parent, "[&*]") && value.isKnown() && value.isIntValue() && value.intvalue==0) { + if (Token::Match(parent, "[&*]") && astIsIntegral(parent, true) && value.isKnown() && value.isIntValue() && + value.intvalue == 0) { setTokenValue(parent, value, settings); return; } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 4b94009b5..63f1606e7 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4094,6 +4094,10 @@ private: " unsigned long long u{};\n" "};\n"); ASSERT_EQUALS("", errout.str()); + + // #8358 + check("void f(double d) { if ((d * 0) != 0) {} }"); + ASSERT_EQUALS("", errout.str()); } void alwaysTrueSymbolic()