diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2020-07-08 12:52:59 +0300 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2020-08-18 12:55:38 +0200 |
commit | 5247af96e3bdf2f28f6e18007fb7e3a7458e0103 (patch) | |
tree | ddf06c7ae7bbacd7df6c9358dcb802bf2954a91d /src/corelib/tools | |
parent | 48911869cb06c96ba76874303b9a49743eb1c4f8 (diff) |
Refine precoditions and logic of array operations
Updated insert() methods:
* Refined Q_ASSERT() checks
* Fixed implementation issues (some of which resulted in
actual crashes)
* Allowed to insert at the end. This is safe as far as I can
tell and actually would allow to simplify considerable chunks
of code (mainly, copyAppend versions to just return
insert at the end)
Updated tests accordingly
Change-Id: I0ba33ae5034ce8d5ff95b753894e95d71ba00257
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qarraydataops.h | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index a97f2da175..c3faa120c4 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -145,7 +145,7 @@ public: { Q_ASSERT(this->isMutable()); Q_ASSERT(!this->isShared()); - Q_ASSERT(where >= this->begin() && where < this->end()); // Use copyAppend at end + Q_ASSERT(where >= this->begin() && where <= this->end()); Q_ASSERT(b <= e); Q_ASSERT(e <= where || b > this->end()); // No overlap Q_ASSERT(size_t(e - b) <= this->allocatedCapacity() - this->size); @@ -159,7 +159,7 @@ public: void insert(T *where, size_t n, parameter_type t) { Q_ASSERT(!this->isShared()); - Q_ASSERT(where >= this->begin() && where < this->end()); // Use copyAppend at end + Q_ASSERT(where >= this->begin() && where <= this->end()); Q_ASSERT(this->allocatedCapacity() - this->size >= n); ::memmove(static_cast<void *>(where + n), static_cast<void *>(where), @@ -351,7 +351,7 @@ struct QGenericArrayOps { Q_ASSERT(this->isMutable()); Q_ASSERT(!this->isShared()); - Q_ASSERT(where >= this->begin() && where < this->end()); // Use copyAppend at end + Q_ASSERT(where >= this->begin() && where <= this->end()); Q_ASSERT(b <= e); Q_ASSERT(e <= where || b > this->end()); // No overlap Q_ASSERT(size_t(e - b) <= this->allocatedCapacity() - this->size); @@ -388,10 +388,10 @@ struct QGenericArrayOps } destroyer(writeIter); // Construct new elements in array - do { + while (writeIter != step1End) { --readIter, --writeIter; new (writeIter) T(*readIter); - } while (writeIter != step1End); + } while (writeIter != end) { --e, --writeIter; @@ -450,10 +450,10 @@ struct QGenericArrayOps } destroyer(writeIter); // Construct new elements in array - do { + while (writeIter != step1End) { --readIter, --writeIter; new (writeIter) T(*readIter); - } while (writeIter != step1End); + } while (writeIter != end) { --n, --writeIter; @@ -551,7 +551,7 @@ struct QMovableArrayOps { Q_ASSERT(this->isMutable()); Q_ASSERT(!this->isShared()); - Q_ASSERT(where >= this->begin() && where < this->end()); // Use copyAppend at end + Q_ASSERT(where >= this->begin() && where <= this->end()); Q_ASSERT(b <= e); Q_ASSERT(e <= where || b > this->end()); // No overlap Q_ASSERT(size_t(e - b) <= this->allocatedCapacity() - this->size); |