From 596f75e2afb87bc7eefa44bec06068582a2d48d2 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 1 Jul 2022 10:48:32 +0200 Subject: [PATCH] Fix FP compareValueOutOfTypeRangeError (#4245) * Fix FP compareValueOutOfTypeRangeError * Remove suppressions --- lib/checkcondition.cpp | 2 ++ test/cfg/googletest.cpp | 4 ++-- test/testcondition.cpp | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index cf082e1dc..63438d5fe 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -1803,6 +1803,8 @@ void CheckCondition::checkCompareValueOutOfTypeRange() continue; if (valueTok->getKnownIntValue() < 0 && valueTok->valueType() && valueTok->valueType()->sign != ValueType::Sign::SIGNED) continue; + if (valueTok->valueType() && valueTok->valueType()->isTypeEqual(typeTok->valueType())) + continue; int bits = 0; switch (typeTok->valueType()->type) { case ValueType::Type::BOOL: diff --git a/test/cfg/googletest.cpp b/test/cfg/googletest.cpp index 26b671e98..37234a703 100644 --- a/test/cfg/googletest.cpp +++ b/test/cfg/googletest.cpp @@ -71,8 +71,8 @@ TEST(Test, warning_in_assert_macros) ASSERT_GE(i, i); unsigned int u = errno; - // cppcheck-suppress [unsignedPositive, compareValueOutOfTypeRangeError] + // cppcheck-suppress [unsignedPositive] ASSERT_GE(u, 0); - // cppcheck-suppress [unsignedLessThanZero, compareValueOutOfTypeRangeError] + // cppcheck-suppress [unsignedLessThanZero] ASSERT_LT(u, 0); } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index b3176619d..5a2fb09a8 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -5258,6 +5258,12 @@ private: "}", &settingsUnix64); ASSERT_EQUALS("", errout.str()); + check("int f(int x) {\n" + " const int i = 0xFFFFFFFF;\n" + " if (x == i) {}\n" + "}", &settingsUnix64); + ASSERT_EQUALS("", errout.str()); + check("void f() {\n" " char c;\n" " if ((c = foo()) != -1) {}\n"