diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-03-24 12:53:27 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-05 05:23:07 +0200 |
commit | f1540a2966ce911e9a5d5754e53f6026e3c26d22 (patch) | |
tree | 91c60cfa43392dac8152179434099471c4e69bca /src/corelib/tools | |
parent | 3e930baa98b4382b76aea5ed6ffdcfb60cdce2d4 (diff) |
Fix capacity reservation for shared QByteArray
We can squeeze, but not by discarding elements. Make sure the size of
the object stays intact after changing the reserved capacity.
I've also added unit tests for other containers, just to be sure.
Task-number: QTBUG-37750
Change-Id: I5135b095943b7589423c51cebcb52af792468e61
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qbytearray.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index b0a6971964..0a2f7a9e53 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -462,7 +462,7 @@ inline int QByteArray::capacity() const inline void QByteArray::reserve(int asize) { if (d->ref.isShared() || uint(asize) + 1u > d->alloc) { - reallocData(uint(asize) + 1u, d->detachFlags() | Data::CapacityReserved); + reallocData(qMax(uint(size()), uint(asize)) + 1u, d->detachFlags() | Data::CapacityReserved); } else { // cannot set unconditionally, since d could be the shared_null or // otherwise static |