diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index b0029e2af79..67930863f2a 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -88,9 +88,9 @@ static void checkWarnMessage(const QIODevice *device, const char *function, cons #define CHECK_MAXBYTEARRAYSIZE(function) \ do { \ - if (maxSize >= QByteArray::max_size()) { \ + if (maxSize >= QByteArray::maxSize()) { \ checkWarnMessage(this, #function, "maxSize argument exceeds QByteArray size limit"); \ - maxSize = QByteArray::max_size() - 1; \ + maxSize = QByteArray::maxSize() - 1; \ } \ } while (0) @@ -1242,7 +1242,7 @@ QByteArray QIODevice::readAll() : d->buffer.size()); qint64 readResult; do { - if (readBytes + readChunkSize >= QByteArray::max_size()) { + if (readBytes + readChunkSize >= QByteArray::maxSize()) { // If resize would fail, don't read more, return what we have. break; } @@ -1256,8 +1256,8 @@ QByteArray QIODevice::readAll() } else { // Read it all in one go. readBytes -= d->pos; - if (readBytes >= QByteArray::max_size()) - readBytes = QByteArray::max_size(); + if (readBytes >= QByteArray::maxSize()) + readBytes = QByteArray::maxSize(); result.resize(readBytes); readBytes = d->read(result.data(), readBytes); } @@ -1448,7 +1448,7 @@ QByteArray QIODevice::readLine(qint64 maxSize) qint64 readBytes = 0; if (maxSize == 0) { // Size is unknown, read incrementally. - maxSize = QByteArray::max_size() - 1; + maxSize = QByteArray::maxSize() - 1; // The first iteration needs to leave an extra byte for the terminating null result.resize(1); diff --git a/src/corelib/serialization/qcborstreamreader.cpp b/src/corelib/serialization/qcborstreamreader.cpp index 863c24534aa..493d1b94caa 100644 --- a/src/corelib/serialization/qcborstreamreader.cpp +++ b/src/corelib/serialization/qcborstreamreader.cpp @@ -1748,7 +1748,7 @@ QCborStreamReaderPrivate::readStringChunk_byte(ReadStringChunk params, qsizetype // the distinction between DataTooLarge and OOM is mostly for // compatibility with Qt 5; in Qt 6, we could consider everything // to be OOM. - handleError(newSize > QByteArray::max_size() ? CborErrorDataTooLarge: CborErrorOutOfMemory); + handleError(newSize > QByteArray::maxSize() ? CborErrorDataTooLarge: CborErrorOutOfMemory); return -1; } @@ -1787,7 +1787,7 @@ QCborStreamReaderPrivate::readStringChunk_unicode(ReadStringChunk params, qsizet // conversion uses the same number of words or less. qsizetype currentSize = params.string->size(); size_t newSize = size_t(utf8len) + size_t(currentSize); // can't overflow - if (utf8len > QString::max_size() || qsizetype(newSize) < 0) { + if (utf8len > QString::maxSize() || qsizetype(newSize) < 0) { handleError(CborErrorDataTooLarge); return -1; } diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index cd0b8421117..830cf00ea3c 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -1808,7 +1808,7 @@ void QCborContainerPrivate::decodeStringFromCbor(QCborStreamReader &reader) // add space for aligned ByteData (this can't overflow) offset += sizeof(QtCbor::ByteData) + alignof(QtCbor::ByteData); offset &= ~(alignof(QtCbor::ByteData) - 1); - if (offset > size_t(QByteArray::max_size())) { + if (offset > size_t(QByteArray::maxSize())) { // overflow setErrorInReader(reader, { QCborError::DataTooLarge }); return; @@ -1821,9 +1821,9 @@ void QCborContainerPrivate::decodeStringFromCbor(QCborStreamReader &reader) // so capa how much we allocate newCapacity = offset + MaxMemoryIncrement - EstimatedOverhead; } - if (newCapacity > size_t(QByteArray::max_size())) { + if (newCapacity > size_t(QByteArray::maxSize())) { // this may cause an allocation failure - newCapacity = QByteArray::max_size(); + newCapacity = QByteArray::maxSize(); } if (newCapacity > size_t(data.capacity())) data.reserve(newCapacity); @@ -1874,7 +1874,7 @@ void QCborContainerPrivate::decodeStringFromCbor(QCborStreamReader &reader) // check that this UTF-8 text string can be loaded onto a QString if (e.type == QCborValue::String) { - if (Q_UNLIKELY(b->len > QString::max_size())) { + if (Q_UNLIKELY(b->len > QString::maxSize())) { setErrorInReader(reader, { QCborError::DataTooLarge }); status = QCborStreamReader::Error; } diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 2e8aeed9f54..af22ff81bc3 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -800,7 +800,7 @@ QByteArray qUncompress(const uchar* data, qsizetype nbytes) return QByteArray(); } - constexpr auto MaxDecompressedSize = size_t(QByteArray::max_size()); + constexpr auto MaxDecompressedSize = size_t(QByteArray::maxSize()); if constexpr (MaxDecompressedSize < std::numeric_limits::max()) { if (expectedSize > MaxDecompressedSize) return tooMuchData(ZLibOp::Decompression); diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp index 06457591189..66de1f59c06 100644 --- a/src/corelib/tools/qringbuffer.cpp +++ b/src/corelib/tools/qringbuffer.cpp @@ -90,7 +90,7 @@ void QRingBuffer::free(qint64 bytes) clear(); // try to minify/squeeze us } } else { - Q_ASSERT(bytes < QByteArray::max_size()); + Q_ASSERT(bytes < QByteArray::maxSize()); chunk.advance(bytes); bufferSize -= bytes; } @@ -105,7 +105,7 @@ void QRingBuffer::free(qint64 bytes) char *QRingBuffer::reserve(qint64 bytes) { - Q_ASSERT(bytes > 0 && bytes < QByteArray::max_size()); + Q_ASSERT(bytes > 0 && bytes < QByteArray::maxSize()); const qsizetype chunkSize = qMax(qint64(basicBlockSize), bytes); qsizetype tail = 0; @@ -135,7 +135,7 @@ char *QRingBuffer::reserve(qint64 bytes) */ char *QRingBuffer::reserveFront(qint64 bytes) { - Q_ASSERT(bytes > 0 && bytes < QByteArray::max_size()); + Q_ASSERT(bytes > 0 && bytes < QByteArray::maxSize()); const qsizetype chunkSize = qMax(qint64(basicBlockSize), bytes); if (bufferSize == 0) { @@ -181,7 +181,7 @@ void QRingBuffer::chop(qint64 bytes) clear(); // try to minify/squeeze us } } else { - Q_ASSERT(bytes < QByteArray::max_size()); + Q_ASSERT(bytes < QByteArray::maxSize()); chunk.grow(-bytes); bufferSize -= bytes; } diff --git a/src/network/socket/qsctpsocket.cpp b/src/network/socket/qsctpsocket.cpp index 868c9e3785c..7712ddea582 100644 --- a/src/network/socket/qsctpsocket.cpp +++ b/src/network/socket/qsctpsocket.cpp @@ -132,7 +132,7 @@ bool QSctpSocketPrivate::canReadNotification() bytesToRead = 4096; } - Q_ASSERT((datagramSize + qsizetype(bytesToRead)) < QByteArray::max_size()); + Q_ASSERT((datagramSize + qsizetype(bytesToRead)) < QByteArray::maxSize()); incomingDatagram.resize(datagramSize + int(bytesToRead)); #if defined (QSCTPSOCKET_DEBUG) diff --git a/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp b/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp index 05e3c7bc236..2cec8f3139a 100644 --- a/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp +++ b/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp @@ -898,7 +898,7 @@ void tst_QCborStreamReader::validation_data() // Add QCborStreamReader-specific limitations due to use of QByteArray and // QString, which are allocated by QArrayData::allocate(). const qsizetype MaxInvalid = std::numeric_limits::max(); - const qsizetype MinInvalid = QByteArray::max_size() + 1; + const qsizetype MinInvalid = QByteArray::maxSize() + 1; addValidationColumns(); addValidationData(MinInvalid); @@ -975,7 +975,7 @@ void tst_QCborStreamReader::validation() void tst_QCborStreamReader::hugeDeviceValidation_data() { - addValidationHugeDevice(QByteArray::max_size() + 1, QString::max_size() + 1); + addValidationHugeDevice(QByteArray::maxSize() + 1, QString::maxSize() + 1); } void tst_QCborStreamReader::hugeDeviceValidation() diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index 04d90bcf9d1..55ef4700950 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -2488,7 +2488,7 @@ void tst_QCborValue::validation_data() // Add QCborStreamReader-specific limitations due to use of QByteArray and // QString, which are allocated by QArrayData::allocate(). const qsizetype MaxInvalid = std::numeric_limits::max(); - const qsizetype MinInvalid = QByteArray::max_size() + 1 - sizeof(QByteArray::size_type); + const qsizetype MinInvalid = QByteArray::maxSize() + 1 - sizeof(QByteArray::size_type); addValidationColumns(); addValidationData(MinInvalid); addValidationLargeData(MinInvalid, MaxInvalid); @@ -2663,7 +2663,7 @@ void tst_QCborValue::hugeDeviceValidation_data() { // because QCborValue will attempt to retain the original string in UTF-8, // the size which it can't store is actually the byte array size - addValidationHugeDevice(QByteArray::max_size() + 1, QByteArray::max_size() + 1); + addValidationHugeDevice(QByteArray::maxSize() + 1, QByteArray::maxSize() + 1); } void tst_QCborValue::hugeDeviceValidation()