Skip to content

Commit 742df60

Browse files
Refs #13814 FP compareValueOutOfTypeRangeError with INT_MAX (#8483)
1 parent eb00a42 commit 742df60

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/checkcondition.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,8 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
19871987
continue;
19881988
if (valueTok->getKnownIntValue() < 0 && valueTok->valueType() && valueTok->valueType()->sign != ValueType::Sign::SIGNED)
19891989
continue;
1990+
if (typeTok->isLiteral())
1991+
continue;
19901992
std::uint8_t bits = 0;
19911993
switch (typeTok->valueType()->type) {
19921994
case ValueType::Type::BOOL:

test/cfg/std.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void test_int32_min() {
4545
}
4646

4747
void test_int64_min() {
48-
// cppcheck-suppress compareValueOutOfTypeRangeError ; tests that INT64_MIN is a signed expression
48+
// TODO cppcheck-suppress knownConditionTrueFalse // #13814
4949
if (INT64_MIN < 0) {}
5050
}
5151

test/testcondition.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6393,6 +6393,13 @@ class TestCondition : public TestFixture {
63936393
ASSERT_EQUALS("[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned int &' against value 4294967295. Condition is always true. [compareValueOutOfTypeRangeError]\n"
63946394
"[test.cpp:4:13]: (style) Comparing expression of type 'const unsigned int &' against value 4294967295. Condition is always false. [compareValueOutOfTypeRangeError]\n",
63956395
errout_str());
6396+
6397+
check("void f() {\n"
6398+
" long long ll = 1024 * 1024 * 1024;\n"
6399+
" if (ll * 8 < INT_MAX) {}\n"
6400+
" if (INT_MAX > ll * 8) {}\n"
6401+
"}\n");
6402+
ASSERT_EQUALS("", errout_str());
63966403
}
63976404

63986405
void knownConditionCast() {

0 commit comments

Comments
 (0)