From 6abfc992b9d70837d42fcef3f2e2637464063899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Wed, 4 Apr 2012 15:00:41 +0200 Subject: Make reallocData() take (unsigned) size, including null The parameter represents an allocation size and unsigned matches the Q*Data::alloc member it ultimately represents (even if they currently differ in accounting for the null). There's still work up for grabs to ensure we avoid integer overflows when growing. Change-Id: Ib092fec37ec2ceed37bebfdc52e2de27b336328f Reviewed-by: Thiago Macieira --- src/corelib/tools/qbytearray.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/corelib/tools/qbytearray.h') diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 37c5f72040..287245182a 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -406,7 +406,7 @@ private: static const QStaticByteArrayData<1> shared_null; static const QStaticByteArrayData<1> shared_empty; Data *d; - void reallocData(int alloc, bool grow = false); + void reallocData(uint alloc, bool grow = false); void expand(int i); QByteArray nulTerminated() const; @@ -445,7 +445,7 @@ inline const char *QByteArray::data() const inline const char *QByteArray::constData() const { return d->data(); } inline void QByteArray::detach() -{ if (d->ref.isShared() || (d->offset != sizeof(QByteArrayData))) reallocData(d->size); } +{ if (d->ref.isShared() || (d->offset != sizeof(QByteArrayData))) reallocData(uint(d->size) + 1u); } inline bool QByteArray::isDetached() const { return !d->ref.isShared(); } inline QByteArray::QByteArray(const QByteArray &a) : d(a.d) @@ -457,7 +457,7 @@ inline int QByteArray::capacity() const inline void QByteArray::reserve(int asize) { if (d->ref.isShared() || asize > int(d->alloc)) - reallocData(asize); + reallocData(uint(asize) + 1u); if (!d->capacityReserved) { // cannot set unconditionally, since d could be the shared_null/shared_empty (which is const) @@ -468,7 +468,7 @@ inline void QByteArray::reserve(int asize) inline void QByteArray::squeeze() { if (d->ref.isShared() || d->size < int(d->alloc)) - reallocData(d->size); + reallocData(uint(d->size) + 1u); if (d->capacityReserved) { // cannot set unconditionally, since d could be shared_null or -- cgit v1.2.3