From ea546c05f13858ca99bb3d8342131cae39d627c2 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Fri, 9 Sep 2011 11:02:06 +0200 Subject: [PATCH] QByteArray's shared_null and shared_empty should be const QByteArray::squeeze() needs to make sure to detach if the data is shared, otherwise it would end up crashing when squeeze() is called on a QByteArray using the shared_null or shared_empty. Change-Id: I89c178659d8c7448681304f050fd69e17b2387de Reviewed-on: http://codereview.qt-project.org/4528 Reviewed-by: Qt Sanity Bot Reviewed-by: Lars Knoll --- src/corelib/tools/qbytearray.cpp | 8 ++++---- src/corelib/tools/qbytearray.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 11ebd8a103e..fc4f4dc67f4 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -614,10 +614,10 @@ static inline char qToLower(char c) return c; } -QConstByteArrayData<1> QByteArray::shared_null = { { Q_REFCOUNT_INITIALIZER(-1), - 0, 0, 0, { 0 } }, { 0 } }; -QConstByteArrayData<1> QByteArray::shared_empty = { { Q_REFCOUNT_INITIALIZER(-1), - 0, 0, 0, { 0 } }, { 0 } }; +const QConstByteArrayData<1> QByteArray::shared_null = { { Q_REFCOUNT_INITIALIZER(-1), + 0, 0, 0, { 0 } }, { 0 } }; +const QConstByteArrayData<1> QByteArray::shared_empty = { { Q_REFCOUNT_INITIALIZER(-1), + 0, 0, 0, { 0 } }, { 0 } }; /*! \class QByteArray diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index fdd34b39356..3bb26ba21ee 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -386,8 +386,8 @@ public: private: operator QNoImplicitBoolCast() const; - static QConstByteArrayData<1> shared_null; - static QConstByteArrayData<1> shared_empty; + static const QConstByteArrayData<1> shared_null; + static const QConstByteArrayData<1> shared_empty; Data *d; QByteArray(Data *dd, int /*dummy*/, int /*dummy*/) : d(dd) {} void realloc(int alloc); @@ -442,7 +442,7 @@ inline void QByteArray::reserve(int asize) { if (d->ref != 1 || asize > int(d->alloc)) realloc(asize); d->capacityReserved = true; } inline void QByteArray::squeeze() -{ if (d->size < int(d->alloc)) realloc(d->size); d->capacityReserved = false; } +{ if (d->ref != 1 || d->size < int(d->alloc)) realloc(d->size); d->capacityReserved = false; } class Q_CORE_EXPORT QByteRef { QByteArray &a;