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>
This commit is contained in:
Lars Knoll 2020-11-13 12:33:15 +01:00
parent 7fc302520b
commit f6f68409a4
2 changed files with 6 additions and 6 deletions

View File

@ -3970,10 +3970,8 @@ bool qunsetenv(const char *varName)
\list
\li \c Q_PRIMITIVE_TYPE specifies that \a Type is a POD (plain old
data) type with no constructor or destructor, or else a type where
every bit pattern is a valid object; memset()ting memory to zero
creates a value-initialized instance of the type; and memcpy()ing
creates a valid independent copy of an object.
data) type with no constructor or destructor, or else a type memcpy()ing
creates a valid independent copy of the object.
\li \c Q_RELOCATABLE_TYPE specifies that \a Type has a constructor
and/or a destructor but can be moved in memory using \c
memcpy().

View File

@ -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;