From 116d711cb1a9ebebab1ef98a3cc29af069a8ec4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Tue, 11 Sep 2012 20:06:12 +0200 Subject: Ensure mutating operations are NOT performed on immutable data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Static" and "raw" data are immutable and shouldn't be modified from within the QArrayData API. Adding the asserts here gives us a basic safety net. Change-Id: Ie2fec03fa1ef5a7f73c50e5badf8b8ab863728b4 Reviewed-by: Jędrzej Nowacki Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- src/corelib/tools/qarraydataops.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/corelib/tools/qarraydataops.h') diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index b94c6b50ea..c7ea6ebf86 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -57,6 +57,7 @@ struct QPodArrayOps { void appendInitialize(size_t newSize) { + Q_ASSERT(this->isMutable()); Q_ASSERT(!this->ref.isShared()); Q_ASSERT(newSize > uint(this->size)); Q_ASSERT(newSize <= this->alloc); @@ -67,6 +68,7 @@ struct QPodArrayOps void copyAppend(const T *b, const T *e) { + Q_ASSERT(this->isMutable()); Q_ASSERT(!this->ref.isShared()); Q_ASSERT(b < e); Q_ASSERT(size_t(e - b) <= this->alloc - uint(this->size)); @@ -77,6 +79,7 @@ struct QPodArrayOps void copyAppend(size_t n, const T &t) { + Q_ASSERT(this->isMutable()); Q_ASSERT(!this->ref.isShared()); Q_ASSERT(n <= this->alloc - uint(this->size)); @@ -89,6 +92,7 @@ struct QPodArrayOps void truncate(size_t newSize) { + Q_ASSERT(this->isMutable()); Q_ASSERT(!this->ref.isShared()); Q_ASSERT(newSize < size_t(this->size)); @@ -97,6 +101,7 @@ struct QPodArrayOps void destroyAll() // Call from destructors, ONLY! { + Q_ASSERT(this->isMutable()); Q_ASSERT(this->ref.atomic.load() == 0); // As this is to be called only from destructor, it doesn't need to be @@ -105,6 +110,7 @@ struct QPodArrayOps void insert(T *where, const T *b, const T *e) { + Q_ASSERT(this->isMutable()); Q_ASSERT(!this->ref.isShared()); Q_ASSERT(where >= this->begin() && where < this->end()); // Use copyAppend at end Q_ASSERT(b < e); @@ -118,6 +124,7 @@ struct QPodArrayOps void erase(T *b, T *e) { + Q_ASSERT(this->isMutable()); Q_ASSERT(b < e); Q_ASSERT(b >= this->begin() && b < this->end()); Q_ASSERT(e > this->begin() && e < this->end()); @@ -133,6 +140,7 @@ struct QGenericArrayOps { void appendInitialize(size_t newSize) { + Q_ASSERT(this->isMutable()); Q_ASSERT(!this->ref.isShared()); Q_ASSERT(newSize > uint(this->size)); Q_ASSERT(newSize <= this->alloc); @@ -145,6 +153,7 @@ struct QGenericArrayOps void copyAppend(const T *b, const T *e) { + Q_ASSERT(this->isMutable()); Q_ASSERT(!this->ref.isShared()); Q_ASSERT(b < e); Q_ASSERT(size_t(e - b) <= this->alloc - uint(this->size)); @@ -158,6 +167,7 @@ struct QGenericArrayOps void copyAppend(size_t n, const T &t) { + Q_ASSERT(this->isMutable()); Q_ASSERT(!this->ref.isShared()); Q_ASSERT(n <= this->alloc - uint(this->size)); @@ -171,6 +181,7 @@ struct QGenericArrayOps void truncate(size_t newSize) { + Q_ASSERT(this->isMutable()); Q_ASSERT(!this->ref.isShared()); Q_ASSERT(newSize < size_t(this->size)); @@ -182,6 +193,7 @@ struct QGenericArrayOps void destroyAll() // Call from destructors, ONLY { + Q_ASSERT(this->isMutable()); // As this is to be called only from destructor, it doesn't need to be // exception safe; size not updated. @@ -196,6 +208,7 @@ struct QGenericArrayOps void insert(T *where, const T *b, const T *e) { + Q_ASSERT(this->isMutable()); Q_ASSERT(!this->ref.isShared()); Q_ASSERT(where >= this->begin() && where < this->end()); // Use copyAppend at end Q_ASSERT(b < e); @@ -261,6 +274,7 @@ struct QGenericArrayOps void erase(T *b, T *e) { + Q_ASSERT(this->isMutable()); Q_ASSERT(b < e); Q_ASSERT(b >= this->begin() && b < this->end()); Q_ASSERT(e > this->begin() && e < this->end()); @@ -290,6 +304,7 @@ struct QMovableArrayOps void insert(T *where, const T *b, const T *e) { + Q_ASSERT(this->isMutable()); Q_ASSERT(!this->ref.isShared()); Q_ASSERT(where >= this->begin() && where < this->end()); // Use copyAppend at end Q_ASSERT(b < e); @@ -354,6 +369,7 @@ struct QMovableArrayOps void erase(T *b, T *e) { + Q_ASSERT(this->isMutable()); Q_ASSERT(b < e); Q_ASSERT(b >= this->begin() && b < this->end()); Q_ASSERT(e > this->begin() && e < this->end()); -- cgit v1.2.3