diff options
| author | Lars Knoll <lars.knoll@qt.io> | 2020-11-13 12:33:15 +0100 |
|---|---|---|
| committer | Lars Knoll <lars.knoll@qt.io> | 2020-11-17 11:47:57 +0100 |
| commit | f6f68409a40beaa5f034c411dd7e296c7828d8fd (patch) | |
| tree | ee4f470b384269db88f20b5aa5c4947ee05e889c /src/corelib/tools/qarraydataops.h | |
| parent | 7fc302520b905fc40cc0fa439d3a2e9dbff3e5a6 (diff) | |
Don't initialize POD types with memset(0)
This is dangerous as at least pointers to member objects/data
are not always zero initialized.
Change-Id: I1250e101ab73cd816694315fc9130f4d486b9feb
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydataops.h')
| -rw-r--r-- | src/corelib/tools/qarraydataops.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index c1ae93dc104..5f43ed3dc0d 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -83,8 +83,11 @@ public: Q_ASSERT(newSize > this->size); Q_ASSERT(newSize - this->size <= this->freeSpaceAtEnd()); - ::memset(static_cast<void *>(this->end()), 0, (newSize - this->size) * sizeof(T)); + T *where = this->end(); this->size = qsizetype(newSize); + const T *e = this->end(); + while (where != e) + *where++ = T(); } void copyAppend(const T *b, const T *e) noexcept @@ -675,7 +678,6 @@ protected: using DataPointer = QArrayDataPointer<T>; public: - // using QGenericArrayOps<T>::appendInitialize; // using QGenericArrayOps<T>::copyAppend; // using QGenericArrayOps<T>::moveAppend; // using QGenericArrayOps<T>::truncate; |
