summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qbytearray
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-12-16 10:34:38 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-12-16 23:25:47 +0100
commitb1938e5787425c39d6e9f6a41605338d1822c86b (patch)
tree5ba1f415b7561269cc9d16a314fdb4e3744cf8cb /tests/auto/corelib/text/qbytearray
parentcc6185fb2b3d5df433aaf69fb6596c55f2361ba3 (diff)
tst_QByteArray: fix UB (signed overflow)
The first case is simple, as it's a static overflow. Theoretically, the compiler would be allowed to just remove the complete function as dead code. This is an error left from the port from int to qsizetype: Qt 5.15 there has uint(MaxAllocSize) + 1, so use quint here again, qint64 is wrong. In the second case, we _may_ reach alloc == MaxAllocSize. Check that, if we do, we don't then add 1 to it. Pick-to: 6.3 6.2 Change-Id: I93044ed6f1b77559642fa1e4e8f313cf59eeeb79 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/corelib/text/qbytearray')
-rw-r--r--tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
index 0f1f00bf6c..cecd0f1584 100644
--- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
@@ -1386,7 +1386,7 @@ void tst_QByteArray::blockSizeCalculations()
QCOMPARE(qCalculateGrowingBlockSize(MaxAllocSize/2, 2, 1).elementCount, qsizetype(MaxAllocSize)/2);
// error conditions
- QCOMPARE(qCalculateBlockSize(qint64(MaxAllocSize) + 1, 1), qsizetype(-1));
+ QCOMPARE(qCalculateBlockSize(quint64(MaxAllocSize) + 1, 1), qsizetype(-1));
QCOMPARE(qCalculateBlockSize(qsizetype(-1), 1), qsizetype(-1));
QCOMPARE(qCalculateBlockSize(MaxAllocSize, 1, 1), qsizetype(-1));
QCOMPARE(qCalculateBlockSize(MaxAllocSize/2 + 1, 2), qsizetype(-1));
@@ -1443,7 +1443,8 @@ void tst_QByteArray::blockSizeCalculations()
QVERIFY(checkSize(alloc, qsizetype(MaxAllocSize) / elementSize));
// the next allocation should be invalid
- QCOMPARE(qCalculateGrowingBlockSize(alloc + 1, elementSize).size, qsizetype(-1));
+ if (alloc < MaxAllocSize) // lest alloc + 1 overflows (= UB)
+ QCOMPARE(qCalculateGrowingBlockSize(alloc + 1, elementSize).size, qsizetype(-1));
}
}