Fix users of static max_size()
Container::max_size() is a _non-static_ member function in the STL, so we can't call it as C::max_size(). Instead, use the newly-added, Qt-style camel-case maxSize(), which we will keep static constexpr. Task-number: QTBUG-128450 Change-Id: I839df90a91cced85f000c7d2744ba547f629ed98 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit 6c15f99853c4cecd9285e189a441392a397b0f82) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
1d725c0094
commit
6978951d5e
@ -88,9 +88,9 @@ static void checkWarnMessage(const QIODevice *device, const char *function, cons
|
|||||||
|
|
||||||
#define CHECK_MAXBYTEARRAYSIZE(function) \
|
#define CHECK_MAXBYTEARRAYSIZE(function) \
|
||||||
do { \
|
do { \
|
||||||
if (maxSize >= QByteArray::max_size()) { \
|
if (maxSize >= QByteArray::maxSize()) { \
|
||||||
checkWarnMessage(this, #function, "maxSize argument exceeds QByteArray size limit"); \
|
checkWarnMessage(this, #function, "maxSize argument exceeds QByteArray size limit"); \
|
||||||
maxSize = QByteArray::max_size() - 1; \
|
maxSize = QByteArray::maxSize() - 1; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -1242,7 +1242,7 @@ QByteArray QIODevice::readAll()
|
|||||||
: d->buffer.size());
|
: d->buffer.size());
|
||||||
qint64 readResult;
|
qint64 readResult;
|
||||||
do {
|
do {
|
||||||
if (readBytes + readChunkSize >= QByteArray::max_size()) {
|
if (readBytes + readChunkSize >= QByteArray::maxSize()) {
|
||||||
// If resize would fail, don't read more, return what we have.
|
// If resize would fail, don't read more, return what we have.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1256,8 +1256,8 @@ QByteArray QIODevice::readAll()
|
|||||||
} else {
|
} else {
|
||||||
// Read it all in one go.
|
// Read it all in one go.
|
||||||
readBytes -= d->pos;
|
readBytes -= d->pos;
|
||||||
if (readBytes >= QByteArray::max_size())
|
if (readBytes >= QByteArray::maxSize())
|
||||||
readBytes = QByteArray::max_size();
|
readBytes = QByteArray::maxSize();
|
||||||
result.resize(readBytes);
|
result.resize(readBytes);
|
||||||
readBytes = d->read(result.data(), readBytes);
|
readBytes = d->read(result.data(), readBytes);
|
||||||
}
|
}
|
||||||
@ -1448,7 +1448,7 @@ QByteArray QIODevice::readLine(qint64 maxSize)
|
|||||||
qint64 readBytes = 0;
|
qint64 readBytes = 0;
|
||||||
if (maxSize == 0) {
|
if (maxSize == 0) {
|
||||||
// Size is unknown, read incrementally.
|
// 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
|
// The first iteration needs to leave an extra byte for the terminating null
|
||||||
result.resize(1);
|
result.resize(1);
|
||||||
|
@ -1748,7 +1748,7 @@ QCborStreamReaderPrivate::readStringChunk_byte(ReadStringChunk params, qsizetype
|
|||||||
// the distinction between DataTooLarge and OOM is mostly for
|
// the distinction between DataTooLarge and OOM is mostly for
|
||||||
// compatibility with Qt 5; in Qt 6, we could consider everything
|
// compatibility with Qt 5; in Qt 6, we could consider everything
|
||||||
// to be OOM.
|
// to be OOM.
|
||||||
handleError(newSize > QByteArray::max_size() ? CborErrorDataTooLarge: CborErrorOutOfMemory);
|
handleError(newSize > QByteArray::maxSize() ? CborErrorDataTooLarge: CborErrorOutOfMemory);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1787,7 +1787,7 @@ QCborStreamReaderPrivate::readStringChunk_unicode(ReadStringChunk params, qsizet
|
|||||||
// conversion uses the same number of words or less.
|
// conversion uses the same number of words or less.
|
||||||
qsizetype currentSize = params.string->size();
|
qsizetype currentSize = params.string->size();
|
||||||
size_t newSize = size_t(utf8len) + size_t(currentSize); // can't overflow
|
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);
|
handleError(CborErrorDataTooLarge);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1808,7 +1808,7 @@ void QCborContainerPrivate::decodeStringFromCbor(QCborStreamReader &reader)
|
|||||||
// add space for aligned ByteData (this can't overflow)
|
// add space for aligned ByteData (this can't overflow)
|
||||||
offset += sizeof(QtCbor::ByteData) + alignof(QtCbor::ByteData);
|
offset += sizeof(QtCbor::ByteData) + alignof(QtCbor::ByteData);
|
||||||
offset &= ~(alignof(QtCbor::ByteData) - 1);
|
offset &= ~(alignof(QtCbor::ByteData) - 1);
|
||||||
if (offset > size_t(QByteArray::max_size())) {
|
if (offset > size_t(QByteArray::maxSize())) {
|
||||||
// overflow
|
// overflow
|
||||||
setErrorInReader(reader, { QCborError::DataTooLarge });
|
setErrorInReader(reader, { QCborError::DataTooLarge });
|
||||||
return;
|
return;
|
||||||
@ -1821,9 +1821,9 @@ void QCborContainerPrivate::decodeStringFromCbor(QCborStreamReader &reader)
|
|||||||
// so capa how much we allocate
|
// so capa how much we allocate
|
||||||
newCapacity = offset + MaxMemoryIncrement - EstimatedOverhead;
|
newCapacity = offset + MaxMemoryIncrement - EstimatedOverhead;
|
||||||
}
|
}
|
||||||
if (newCapacity > size_t(QByteArray::max_size())) {
|
if (newCapacity > size_t(QByteArray::maxSize())) {
|
||||||
// this may cause an allocation failure
|
// this may cause an allocation failure
|
||||||
newCapacity = QByteArray::max_size();
|
newCapacity = QByteArray::maxSize();
|
||||||
}
|
}
|
||||||
if (newCapacity > size_t(data.capacity()))
|
if (newCapacity > size_t(data.capacity()))
|
||||||
data.reserve(newCapacity);
|
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
|
// check that this UTF-8 text string can be loaded onto a QString
|
||||||
if (e.type == QCborValue::String) {
|
if (e.type == QCborValue::String) {
|
||||||
if (Q_UNLIKELY(b->len > QString::max_size())) {
|
if (Q_UNLIKELY(b->len > QString::maxSize())) {
|
||||||
setErrorInReader(reader, { QCborError::DataTooLarge });
|
setErrorInReader(reader, { QCborError::DataTooLarge });
|
||||||
status = QCborStreamReader::Error;
|
status = QCborStreamReader::Error;
|
||||||
}
|
}
|
||||||
|
@ -800,7 +800,7 @@ QByteArray qUncompress(const uchar* data, qsizetype nbytes)
|
|||||||
return QByteArray();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto MaxDecompressedSize = size_t(QByteArray::max_size());
|
constexpr auto MaxDecompressedSize = size_t(QByteArray::maxSize());
|
||||||
if constexpr (MaxDecompressedSize < std::numeric_limits<CompressSizeHint_t>::max()) {
|
if constexpr (MaxDecompressedSize < std::numeric_limits<CompressSizeHint_t>::max()) {
|
||||||
if (expectedSize > MaxDecompressedSize)
|
if (expectedSize > MaxDecompressedSize)
|
||||||
return tooMuchData(ZLibOp::Decompression);
|
return tooMuchData(ZLibOp::Decompression);
|
||||||
|
@ -90,7 +90,7 @@ void QRingBuffer::free(qint64 bytes)
|
|||||||
clear(); // try to minify/squeeze us
|
clear(); // try to minify/squeeze us
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Q_ASSERT(bytes < QByteArray::max_size());
|
Q_ASSERT(bytes < QByteArray::maxSize());
|
||||||
chunk.advance(bytes);
|
chunk.advance(bytes);
|
||||||
bufferSize -= bytes;
|
bufferSize -= bytes;
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ void QRingBuffer::free(qint64 bytes)
|
|||||||
|
|
||||||
char *QRingBuffer::reserve(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);
|
const qsizetype chunkSize = qMax(qint64(basicBlockSize), bytes);
|
||||||
qsizetype tail = 0;
|
qsizetype tail = 0;
|
||||||
@ -135,7 +135,7 @@ char *QRingBuffer::reserve(qint64 bytes)
|
|||||||
*/
|
*/
|
||||||
char *QRingBuffer::reserveFront(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);
|
const qsizetype chunkSize = qMax(qint64(basicBlockSize), bytes);
|
||||||
if (bufferSize == 0) {
|
if (bufferSize == 0) {
|
||||||
@ -181,7 +181,7 @@ void QRingBuffer::chop(qint64 bytes)
|
|||||||
clear(); // try to minify/squeeze us
|
clear(); // try to minify/squeeze us
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Q_ASSERT(bytes < QByteArray::max_size());
|
Q_ASSERT(bytes < QByteArray::maxSize());
|
||||||
chunk.grow(-bytes);
|
chunk.grow(-bytes);
|
||||||
bufferSize -= bytes;
|
bufferSize -= bytes;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ bool QSctpSocketPrivate::canReadNotification()
|
|||||||
bytesToRead = 4096;
|
bytesToRead = 4096;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT((datagramSize + qsizetype(bytesToRead)) < QByteArray::max_size());
|
Q_ASSERT((datagramSize + qsizetype(bytesToRead)) < QByteArray::maxSize());
|
||||||
incomingDatagram.resize(datagramSize + int(bytesToRead));
|
incomingDatagram.resize(datagramSize + int(bytesToRead));
|
||||||
|
|
||||||
#if defined (QSCTPSOCKET_DEBUG)
|
#if defined (QSCTPSOCKET_DEBUG)
|
||||||
|
@ -898,7 +898,7 @@ void tst_QCborStreamReader::validation_data()
|
|||||||
// Add QCborStreamReader-specific limitations due to use of QByteArray and
|
// Add QCborStreamReader-specific limitations due to use of QByteArray and
|
||||||
// QString, which are allocated by QArrayData::allocate().
|
// QString, which are allocated by QArrayData::allocate().
|
||||||
const qsizetype MaxInvalid = std::numeric_limits<QByteArray::size_type>::max();
|
const qsizetype MaxInvalid = std::numeric_limits<QByteArray::size_type>::max();
|
||||||
const qsizetype MinInvalid = QByteArray::max_size() + 1;
|
const qsizetype MinInvalid = QByteArray::maxSize() + 1;
|
||||||
|
|
||||||
addValidationColumns();
|
addValidationColumns();
|
||||||
addValidationData(MinInvalid);
|
addValidationData(MinInvalid);
|
||||||
@ -975,7 +975,7 @@ void tst_QCborStreamReader::validation()
|
|||||||
|
|
||||||
void tst_QCborStreamReader::hugeDeviceValidation_data()
|
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()
|
void tst_QCborStreamReader::hugeDeviceValidation()
|
||||||
|
@ -2488,7 +2488,7 @@ void tst_QCborValue::validation_data()
|
|||||||
// Add QCborStreamReader-specific limitations due to use of QByteArray and
|
// Add QCborStreamReader-specific limitations due to use of QByteArray and
|
||||||
// QString, which are allocated by QArrayData::allocate().
|
// QString, which are allocated by QArrayData::allocate().
|
||||||
const qsizetype MaxInvalid = std::numeric_limits<QByteArray::size_type>::max();
|
const qsizetype MaxInvalid = std::numeric_limits<QByteArray::size_type>::max();
|
||||||
const qsizetype MinInvalid = QByteArray::max_size() + 1 - sizeof(QByteArray::size_type);
|
const qsizetype MinInvalid = QByteArray::maxSize() + 1 - sizeof(QByteArray::size_type);
|
||||||
addValidationColumns();
|
addValidationColumns();
|
||||||
addValidationData(MinInvalid);
|
addValidationData(MinInvalid);
|
||||||
addValidationLargeData(MinInvalid, MaxInvalid);
|
addValidationLargeData(MinInvalid, MaxInvalid);
|
||||||
@ -2663,7 +2663,7 @@ void tst_QCborValue::hugeDeviceValidation_data()
|
|||||||
{
|
{
|
||||||
// because QCborValue will attempt to retain the original string in UTF-8,
|
// 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
|
// 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()
|
void tst_QCborValue::hugeDeviceValidation()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user