summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbytearray.h
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-04-04 15:00:41 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-11 02:26:41 +0200
commit6abfc992b9d70837d42fcef3f2e2637464063899 (patch)
tree61cc582bba6fba2dc49e5d3d20cebb656895ca40 /src/corelib/tools/qbytearray.h
parentd4f3052a1b210c09976883afbe0fac087171be4f (diff)
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qbytearray.h')
-rw-r--r--src/corelib/tools/qbytearray.h8
1 files changed, 4 insertions, 4 deletions
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