QIODevice: add CHECK_MAXBYTEARRAYSIZE macro

It unifies handling of QByteArray's size limit in read(), readLine()
and will be used in a follow-up change which optimizes the performance
of QIODevice::peek() function.

Change-Id: Idb9fbbe14d9632ee267d2a0e47c8a88603c024a2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Alex Trotsenko 2016-09-30 19:26:48 +03:00
parent 897ef8f200
commit 4518345b80

View File

@ -120,6 +120,14 @@ static void checkWarnMessage(const QIODevice *device, const char *function, cons
} \
} while (0)
#define CHECK_MAXBYTEARRAYSIZE(function) \
do { \
if (maxSize >= MaxByteArraySize) { \
checkWarnMessage(this, #function, "maxSize argument exceeds QByteArray size limit"); \
maxSize = MaxByteArraySize - 1; \
} \
} while (0)
#define CHECK_WRITABLE(function, returnType) \
do { \
if ((d->openMode & WriteOnly) == 0) { \
@ -1149,17 +1157,13 @@ QByteArray QIODevice::read(qint64 maxSize)
QByteArray result;
CHECK_MAXLEN(read, result);
CHECK_MAXBYTEARRAYSIZE(read);
#if defined QIODEVICE_DEBUG
printf("%p QIODevice::read(%lld), d->pos = %lld, d->buffer.size() = %lld\n",
this, maxSize, d->pos, d->buffer.size());
#endif
if (maxSize >= MaxByteArraySize) {
checkWarnMessage(this, "read", "maxSize argument exceeds QByteArray size limit");
maxSize = MaxByteArraySize - 1;
}
qint64 readBytes = 0;
if (maxSize) {
result.resize(int(maxSize));
@ -1393,17 +1397,13 @@ QByteArray QIODevice::readLine(qint64 maxSize)
QByteArray result;
CHECK_MAXLEN(readLine, result);
CHECK_MAXBYTEARRAYSIZE(readLine);
#if defined QIODEVICE_DEBUG
printf("%p QIODevice::readLine(%lld), d->pos = %lld, d->buffer.size() = %lld\n",
this, maxSize, d->pos, d->buffer.size());
#endif
if (maxSize >= MaxByteArraySize) {
qWarning("QIODevice::read: maxSize argument exceeds QByteArray size limit");
maxSize = MaxByteArraySize - 1;
}
result.resize(int(maxSize));
qint64 readBytes = 0;
if (!result.size()) {