You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++] HeapResizableDirectMemory copy constructor writes through nullptr and stores the end iterator as Pointer #121
HeapResizableDirectMemory(const HeapResizableDirectMemory& other)
{
auto mem = Internal::as_bytes(other.Pointer(), other.UsedCapacity());
Pointer() = std::copy(std::execution::par_unseq, mem.begin(), mem.end(), static_cast<std::byte*>(Pointer()));
ReservedCapacity(other.ReservedCapacity());
UsedCapacity(other.UsedCapacity());
}
Pointer() is still nullptr when std::copy runs, so the bytes are written to address 0.
The result of std::copy (the end iterator) is stored as Pointer(), and realloc is later called on it.
OnReservedCapacityChanged also loses the old block when realloc fails (Pointer() = std::realloc(Pointer(), …)).
The existing test GetLastByteByCopy passes this constructor only because UsedCapacity() is 0 there: zero bytes are copied, the "end iterator" is nullptr, and realloc(nullptr, n) behaves like malloc. The test then reads an uninitialised byte of a fresh block and does not check the copy.
Activity