Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,8 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
continue;
if (valueTok->getKnownIntValue() < 0 && valueTok->valueType() && valueTok->valueType()->sign != ValueType::Sign::SIGNED)
continue;
if (typeTok->isLiteral())
continue;
std::uint8_t bits = 0;
switch (typeTok->valueType()->type) {
case ValueType::Type::BOOL:
Expand Down
2 changes: 1 addition & 1 deletion test/cfg/std.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void test_int32_min() {
}

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

Expand Down
7 changes: 7 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6375,6 +6375,13 @@ class TestCondition : public TestFixture {
ASSERT_EQUALS("[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned int &' against value 4294967295. Condition is always true. [compareValueOutOfTypeRangeError]\n"
"[test.cpp:4:13]: (style) Comparing expression of type 'const unsigned int &' against value 4294967295. Condition is always false. [compareValueOutOfTypeRangeError]\n",
errout_str());

check("void f() {\n"
" long long ll = 1024 * 1024 * 1024;\n"
" if (ll * 8 < INT_MAX) {}\n"
" if (INT_MAX > ll * 8) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void knownConditionCast() {
Expand Down
Loading