From cc6a3b61c140465096a4d930d50d2c3fec521271 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 14 Oct 2026 12:59:41 +0200 Subject: [PATCH 1/3] Update checkcondition.cpp --- lib/checkcondition.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 48b2a1ae4bf..fbb18025651 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -2009,7 +2009,8 @@ void CheckConditionImpl::checkCompareValueOutOfTypeRange() for (int i = 0; i < 2; ++i) { const Token * const valueTok = (i == 0) ? tok->astOperand1() : tok->astOperand2(); const Token * const typeTok = valueTok->astSibling(); - if (!valueTok->hasKnownIntValue() || !typeTok->valueType() || typeTok->valueType()->pointer) + const ValueType* const typeVt = typeTok->valueType(); + if (!valueTok->hasKnownIntValue() || !typeVt || typeVt->pointer) continue; if (valueTok->getKnownIntValue() < 0 && valueTok->valueType() && valueTok->valueType()->sign != ValueType::Sign::SIGNED) continue; @@ -2040,11 +2041,11 @@ void CheckConditionImpl::checkCompareValueOutOfTypeRange() } if (bits == 0 || bits >= 63) continue; - - const auto typeMinValue = (typeTok->valueType()->sign == ValueType::Sign::UNSIGNED) ? 0 : (-(1LL << (bits-1))); + + const auto typeMinValue = (typeVt->sign == ValueType::Sign::UNSIGNED) ? 0 : (-(1LL << (bits-1))); const auto unsignedTypeMaxValue = (1LL << bits) - 1LL; - long long typeMaxValue; - if (typeTok->valueType()->sign != ValueType::Sign::SIGNED) + long long typeMaxValue; + if (typeVt->sign != ValueType::Sign::SIGNED && !(typeVt->sign == ValueType::Sign::UNKNOWN_SIGN && typeVt->type == ValueType::Type::CHAR && mSettings.platform.defaultSign == 's')) typeMaxValue = unsignedTypeMaxValue; else if (bits >= mSettings.platform.int_bit && (!valueTok->valueType() || valueTok->valueType()->sign != ValueType::Sign::SIGNED)) typeMaxValue = unsignedTypeMaxValue; @@ -2105,7 +2106,7 @@ void CheckConditionImpl::checkCompareValueOutOfTypeRange() } if (!error || diag(tok)) continue; - compareValueOutOfTypeRangeError(valueTok, typeTok->valueType()->str(), kiv, result); + compareValueOutOfTypeRangeError(valueTok, typeVt->str(), kiv, result); } } } From 9ec3dfbb0c6880b5d85e410948a2b440b5166c45 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 14 Oct 2026 13:00:44 +0200 Subject: [PATCH 2/3] Update testcondition.cpp --- test/testcondition.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 93248837cb3..b23bcc2e20b 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -6652,6 +6652,12 @@ class TestCondition : public TestFixture { "[test.cpp:2:28]: (style) Comparing expression of type 'signed int' against value 2147483647. Condition is always false. [compareValueOutOfTypeRangeError]\n" "[test.cpp:7:17]: (style) Comparing expression of type 'signed int' against value 2147483647. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str()); + + check("void f(char c) {\n" // #11592 + " if (c == 128) {}\n" + "}\n", settingsUnix64); + ASSERT_EQUALS("[test.cpp:2:14]: (style) Comparing expression of type 'char' against value 128. Condition is always false. [compareValueOutOfTypeRangeError]\n", + errout_str()); } void knownConditionCast() { From ca3eda6b5fce76e9ecdb4954ab8e37908abba342 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 14 Oct 2026 13:03:25 +0200 Subject: [PATCH 3/3] Update checkcondition.cpp --- lib/checkcondition.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index fbb18025651..0d423b6f3dd 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -2041,10 +2041,10 @@ void CheckConditionImpl::checkCompareValueOutOfTypeRange() } if (bits == 0 || bits >= 63) continue; - + const auto typeMinValue = (typeVt->sign == ValueType::Sign::UNSIGNED) ? 0 : (-(1LL << (bits-1))); const auto unsignedTypeMaxValue = (1LL << bits) - 1LL; - long long typeMaxValue; + long long typeMaxValue; if (typeVt->sign != ValueType::Sign::SIGNED && !(typeVt->sign == ValueType::Sign::UNKNOWN_SIGN && typeVt->type == ValueType::Type::CHAR && mSettings.platform.defaultSign == 's')) typeMaxValue = unsignedTypeMaxValue; else if (bits >= mSettings.platform.int_bit && (!valueTok->valueType() || valueTok->valueType()->sign != ValueType::Sign::SIGNED))