diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-06-03 15:57:42 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-06-16 14:30:45 +0000 |
commit | ef0f7f424872a27c8397f854eecff753428bcddc (patch) | |
tree | 72cc245da16bc233f7586a312c3ea2890f0ffd6c /src/corelib/io/qiodevice.cpp | |
parent | 8d5516b58541b2ad63497437271f0a4e36ed311d (diff) |
Unify QByteArray::MaxSize and MaxAllocSize
We have established the maximum size qAllocMore can deal with in
commit 880986be2357a1f80827d038d770dc2f80300201 and we should use
it.
The maximum size for byte arrays is reduced by one byte as with
the previous code we could make qAllocMore produce ((1 << 31) - extra)
by passing (1 << 30). That is not a problem for qAllocMore itself
(as long as extra > 0) but it's hard to verify that no related
code casts the total sum back to signed int, which would overflow
to -1.
To make the compiler inline access to the maximum size, a private
enum MaxByteArraySize is provided, which can be used in internal
code.
This fixes the merge of commits
880986be2357a1f80827d038d770dc2f80300201 and
c70658d301e274c3aaa1fb6cebe2a5e56db12779
Change-Id: Idb04856f7c2e53ef383063e7555d3083020ff2b7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qiodevice.cpp')
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 07a2ff8f6b..3c8e97e3c6 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -39,6 +39,7 @@ #include "qfile.h" #include "qstringlist.h" #include "qdir.h" +#include "private/qbytearray_p.h" #include <algorithm> @@ -941,9 +942,9 @@ QByteArray QIODevice::read(qint64 maxSize) Q_UNUSED(d); #endif - if (quint64(maxSize) >= QByteArray::MaxSize) { + if (maxSize >= MaxByteArraySize) { checkWarnMessage(this, "read", "maxSize argument exceeds QByteArray size limit"); - maxSize = QByteArray::MaxSize - 1; + maxSize = MaxByteArraySize - 1; } qint64 readBytes = 0; @@ -995,7 +996,7 @@ QByteArray QIODevice::readAll() // flush internal read buffer if (!(d->openMode & Text) && !d->buffer.isEmpty()) { - if (quint64(d->buffer.size()) >= QByteArray::MaxSize) + if (d->buffer.size() >= MaxByteArraySize) return QByteArray(); result = d->buffer.readAll(); readBytes = result.size(); @@ -1008,7 +1009,7 @@ QByteArray QIODevice::readAll() // Size is unknown, read incrementally. qint64 readResult; do { - if (quint64(readBytes) + QIODEVICE_BUFFERSIZE >= QByteArray::MaxSize) { + if (readBytes + QIODEVICE_BUFFERSIZE >= MaxByteArraySize) { // If resize would fail, don't read more, return what we have. break; } @@ -1020,7 +1021,7 @@ QByteArray QIODevice::readAll() } else { // Read it all in one go. // If resize fails, don't read anything. - if (quint64(readBytes + theSize - d->pos) >= QByteArray::MaxSize) + if (readBytes + theSize - d->pos >= MaxByteArraySize) return QByteArray(); result.resize(int(readBytes + theSize - d->pos)); readBytes += read(result.data() + readBytes, result.size() - readBytes); @@ -1178,9 +1179,9 @@ QByteArray QIODevice::readLine(qint64 maxSize) Q_UNUSED(d); #endif - if (quint64(maxSize) >= QByteArray::MaxSize) { + if (maxSize >= MaxByteArraySize) { qWarning("QIODevice::read: maxSize argument exceeds QByteArray size limit"); - maxSize = QByteArray::MaxSize - 1; + maxSize = MaxByteArraySize - 1; } result.resize(int(maxSize)); @@ -1188,7 +1189,7 @@ QByteArray QIODevice::readLine(qint64 maxSize) if (!result.size()) { // If resize fails or maxSize == 0, read incrementally if (maxSize == 0) - maxSize = QByteArray::MaxSize - 1; + maxSize = MaxByteArraySize - 1; // The first iteration needs to leave an extra byte for the terminating null result.resize(1); |