From 4518345b80b0ee1101ecb0e7349728abd237aa6e Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Fri, 30 Sep 2016 19:26:48 +0300 Subject: [PATCH] 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 --- src/corelib/io/qiodevice.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index f5b17318bec..c4fc040685b 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -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()) {