[Glacier] When resizing vector use the proper T constructor.

Previously when we static_casted from uint8_t[] to T[] we ended
up not properly initializing the objects in the array. This caused
issues where garbage memory provided by new was treated as a legitimate
object.

Potentially in the future it would make sense to back vectors with
a simple byte array and do memcpys to move objects in and out as
needed.
This commit is contained in:
Drew Galbraith 2023-11-15 12:00:48 -08:00
parent 7c105c8a31
commit 792e5155ba
1 changed files with 6 additions and 4 deletions

View File

@ -69,11 +69,13 @@ class Vector {
template <typename T>
void Vector<T>::Resize(uint64_t capacity) {
T* new_data = reinterpret_cast<T*>(new uint8_t[capacity * sizeof(T)]);
for (uint64_t i = 0; i < size_; i++) {
new_data[i] = glcr::Move(data_[i]);
T* new_data = new T[capacity];
if (data_) {
for (uint64_t i = 0; i < size_; i++) {
new_data[i] = glcr::Move(data_[i]);
}
delete[] data_;
}
delete[] data_;
data_ = new_data;
capacity_ = capacity;
}