diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2016-09-30 19:26:48 +0300 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2016-10-01 17:36:50 +0000 |
commit | 4518345b80b0ee1101ecb0e7349728abd237aa6e (patch) | |
tree | a4ee6a980f6aee3230d7e04ec210ef5db823e071 /src | |
parent | 897ef8f200d8a07ead49337762b5c95d063cc7e7 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index f5b17318be..c4fc040685 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()) { |