fix nullptr passed to memcmp/memcpy reported by ubsan

This commit is contained in:
Günter Obiltschnig
2021-06-24 07:53:22 +02:00
parent 230812093b
commit 2f33db9053

View File

@@ -191,7 +191,7 @@ public:
if (newCapacity > 0) if (newCapacity > 0)
{ {
ptr = new T[newCapacity]; ptr = new T[newCapacity];
if (preserveContent) if (preserveContent && _ptr)
{ {
std::size_t newSz = _used < newCapacity ? _used : newCapacity; std::size_t newSz = _used < newCapacity ? _used : newCapacity;
std::memcpy(ptr, _ptr, newSz * sizeof(T)); std::memcpy(ptr, _ptr, newSz * sizeof(T));