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/tools/qbytearray.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/tools/qbytearray.cpp')
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 36c1f42995..0ed701f4fa 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -41,6 +41,7 @@ #include "qlocale_p.h" #include "qstringalgorithms_p.h" #include "qscopedpointer.h" +#include "qbytearray_p.h" #include <qdatastream.h> #include <qmath.h> @@ -123,8 +124,8 @@ int qFindByteArray( int qAllocMore(int alloc, int extra) Q_DECL_NOTHROW { - Q_ASSERT(alloc >= 0 && extra >= 0); - Q_ASSERT_X(uint(alloc) <= QByteArray::MaxSize, "qAllocMore", "Requested size is too large!"); + Q_ASSERT(alloc >= 0 && extra >= 0 && extra <= MaxAllocSize); + Q_ASSERT_X(alloc <= MaxAllocSize - extra, "qAllocMore", "Requested size is too large!"); unsigned nalloc = qNextPowerOfTwo(alloc + extra); @@ -838,16 +839,6 @@ static inline char qToLower(char c) */ /*! - \variable QByteArray::MaxSize - \internal - \since 5.4 - - The maximum size of a QByteArray (including a '\0' terminator), in bytes. - Also applies to the maximum storage size of QString and QVector, though - not the number of elements. -*/ - -/*! \enum QByteArray::Base64Option \since 5.2 @@ -1575,7 +1566,7 @@ void QByteArray::reallocData(uint alloc, Data::AllocationOptions options) d = x; } else { if (options & Data::Grow) { - if (alloc > uint(MaxAllocSize) - uint(sizeof(Data))) + if (alloc > MaxByteArraySize) qBadAlloc(); alloc = qAllocMore(alloc, sizeof(Data)); } |