fix nullptr passed to memcmp/memcpy reported by ubsan

This commit is contained in:
Günter Obiltschnig 2021-06-24 07:49:45 +02:00
parent 4508514666
commit 230812093b

View File

@ -159,7 +159,7 @@ public:
if (newCapacity > _capacity) if (newCapacity > _capacity)
{ {
T* ptr = new T[newCapacity]; T* ptr = new T[newCapacity];
if (preserveContent) if (preserveContent && _ptr)
{ {
std::memcpy(ptr, _ptr, _used * sizeof(T)); std::memcpy(ptr, _ptr, _used * sizeof(T));
} }
@ -266,10 +266,11 @@ public:
{ {
if (_used == other._used) if (_used == other._used)
{ {
if (std::memcmp(_ptr, other._ptr, _used * sizeof(T)) == 0) if (_ptr && other._ptr && std::memcmp(_ptr, other._ptr, _used * sizeof(T)) == 0)
{ {
return true; return true;
} }
else return _used == 0;
} }
return false; return false;
} }