Skip to content

Commit 596f75e

Browse files
Fix FP compareValueOutOfTypeRangeError (#4245)
* Fix FP compareValueOutOfTypeRangeError * Remove suppressions
1 parent 27578e9 commit 596f75e

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/checkcondition.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,8 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
18031803
continue;
18041804
if (valueTok->getKnownIntValue() < 0 && valueTok->valueType() && valueTok->valueType()->sign != ValueType::Sign::SIGNED)
18051805
continue;
1806+
if (valueTok->valueType() && valueTok->valueType()->isTypeEqual(typeTok->valueType()))
1807+
continue;
18061808
int bits = 0;
18071809
switch (typeTok->valueType()->type) {
18081810
case ValueType::Type::BOOL:

test/cfg/googletest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ TEST(Test, warning_in_assert_macros)
7171
ASSERT_GE(i, i);
7272

7373
unsigned int u = errno;
74-
// cppcheck-suppress [unsignedPositive, compareValueOutOfTypeRangeError]
74+
// cppcheck-suppress [unsignedPositive]
7575
ASSERT_GE(u, 0);
76-
// cppcheck-suppress [unsignedLessThanZero, compareValueOutOfTypeRangeError]
76+
// cppcheck-suppress [unsignedLessThanZero]
7777
ASSERT_LT(u, 0);
7878
}

test/testcondition.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5258,6 +5258,12 @@ class TestCondition : public TestFixture {
52585258
"}", &settingsUnix64);
52595259
ASSERT_EQUALS("", errout.str());
52605260

5261+
check("int f(int x) {\n"
5262+
" const int i = 0xFFFFFFFF;\n"
5263+
" if (x == i) {}\n"
5264+
"}", &settingsUnix64);
5265+
ASSERT_EQUALS("", errout.str());
5266+
52615267
check("void f() {\n"
52625268
" char c;\n"
52635269
" if ((c = foo()) != -1) {}\n"

0 commit comments

Comments
 (0)