From 1f8efbbb68dfb48d1f3481faf06e55ac478e2826 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Thu, 30 Jun 2022 23:51:06 +0200 Subject: [PATCH 1/2] Fix FP compareValueOutOfTypeRangeError --- lib/checkcondition.cpp | 2 ++ test/testcondition.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index cf082e1dc98..63438d5fe81 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/testcondition.cpp b/test/testcondition.cpp index b3176619dd9..5a2fb09a8d8 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -5258,6 +5258,12 @@ class TestCondition : public TestFixture { "}", &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" From 456b68d6b8ef331a3d8ed82778185a9102537823 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 1 Jul 2022 00:21:52 +0200 Subject: [PATCH 2/2] Remove suppressions --- test/cfg/googletest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cfg/googletest.cpp b/test/cfg/googletest.cpp index 26b671e98d8..37234a703dd 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); }