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 <qt_sanity_bot@ovi.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Bradley T. Hughes 2011-09-09 11:02:06 +02:00 committed by Qt by Nokia
parent ceb3a071d2
commit ea546c05f1
2 changed files with 7 additions and 7 deletions

View File

@ -614,9 +614,9 @@ static inline char qToLower(char c)
return c; return c;
} }
QConstByteArrayData<1> QByteArray::shared_null = { { Q_REFCOUNT_INITIALIZER(-1), const QConstByteArrayData<1> QByteArray::shared_null = { { Q_REFCOUNT_INITIALIZER(-1),
0, 0, 0, { 0 } }, { 0 } }; 0, 0, 0, { 0 } }, { 0 } };
QConstByteArrayData<1> QByteArray::shared_empty = { { Q_REFCOUNT_INITIALIZER(-1), const QConstByteArrayData<1> QByteArray::shared_empty = { { Q_REFCOUNT_INITIALIZER(-1),
0, 0, 0, { 0 } }, { 0 } }; 0, 0, 0, { 0 } }, { 0 } };
/*! /*!

View File

@ -386,8 +386,8 @@ public:
private: private:
operator QNoImplicitBoolCast() const; operator QNoImplicitBoolCast() const;
static QConstByteArrayData<1> shared_null; static const QConstByteArrayData<1> shared_null;
static QConstByteArrayData<1> shared_empty; static const QConstByteArrayData<1> shared_empty;
Data *d; Data *d;
QByteArray(Data *dd, int /*dummy*/, int /*dummy*/) : d(dd) {} QByteArray(Data *dd, int /*dummy*/, int /*dummy*/) : d(dd) {}
void realloc(int alloc); 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; } { if (d->ref != 1 || asize > int(d->alloc)) realloc(asize); d->capacityReserved = true; }
inline void QByteArray::squeeze() 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 { class Q_CORE_EXPORT QByteRef {
QByteArray &a; QByteArray &a;