QTypeRevision: fix support for 8-bit signed segments

The logic in the isValidSegment() function was failing for 8-bit signed
because for them Integer(SegmentUnknown) is -1, so
  (std::numeric_limits<Integer>::max)() < Integer(SegmentUnknown)
was always false (127 < -1) and the function would only return true on
the impossible condition of
  segment >= 0 && segment < -1

Fixes: QTBUG-128848
Pick-to: 6.7 6.5
Change-Id: I8d17b93afd6c2982a099fffdcaeccf126b7a9d02
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit ddfcc0734875cdee2c169bf2ecb1546bddba6e98)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2024-09-11 16:03:47 -07:00 committed by Qt Cherry-pick Bot
parent 43003ccbce
commit 4f30a4426c
2 changed files with 6 additions and 4 deletions

View File

@ -45,9 +45,11 @@ public:
static constexpr bool isValidSegment(Integer segment) static constexpr bool isValidSegment(Integer segment)
{ {
// using extra parentheses around max to avoid expanding it if it is a macro // using extra parentheses around max to avoid expanding it if it is a macro
// and adding zero to cause it to be promoted
constexpr auto Max = (std::numeric_limits<Integer>::max)() + 0;
constexpr bool HasSufficientRange = Max >= SegmentUnknown;
return segment >= Integer(0) return segment >= Integer(0)
&& ((std::numeric_limits<Integer>::max)() < Integer(SegmentUnknown) && (!HasSufficientRange || segment < Integer(SegmentUnknown));
|| segment < Integer(SegmentUnknown));
} }
template<typename Major, typename Minor, template<typename Major, typename Minor,

View File

@ -95,7 +95,7 @@ void tst_QTypeRevision::qTypeRevision()
void tst_QTypeRevision::qTypeRevisionTypes() void tst_QTypeRevision::qTypeRevisionTypes()
{ {
compileTestRevision<quint8>(); compileTestRevision<quint8>();
// compileTestRevision<qint8>(); compileTestRevision<qint8>();
compileTestRevision<quint16>(); compileTestRevision<quint16>();
compileTestRevision<qint16>(); compileTestRevision<qint16>();
compileTestRevision<quint32>(); compileTestRevision<quint32>();
@ -104,7 +104,7 @@ void tst_QTypeRevision::qTypeRevisionTypes()
compileTestRevision<qint64>(); compileTestRevision<qint64>();
compileTestRevision<long>(); compileTestRevision<long>();
compileTestRevision<ulong>(); compileTestRevision<ulong>();
// compileTestRevision<char>(); compileTestRevision<char>();
QVERIFY(!QTypeRevision::isValidSegment(0xff)); QVERIFY(!QTypeRevision::isValidSegment(0xff));
QVERIFY(!QTypeRevision::isValidSegment(-1)); QVERIFY(!QTypeRevision::isValidSegment(-1));