libluna/Vector: Use bytes instead of count in resize()
This fixes a bug that was causing the heap linked list to become quite corrupted.
This commit is contained in:
parent
e8a401efc2
commit
41203df472
@ -150,6 +150,11 @@ template <typename T> class Vector
|
||||
return m_capacity;
|
||||
}
|
||||
|
||||
usize byte_capacity() const
|
||||
{
|
||||
return m_capacity * sizeof(T);
|
||||
}
|
||||
|
||||
usize size() const
|
||||
{
|
||||
return m_size;
|
||||
@ -162,10 +167,14 @@ template <typename T> class Vector
|
||||
|
||||
Result<void> resize(usize new_capacity)
|
||||
{
|
||||
void* ptr = TRY(realloc_impl(m_data, new_capacity));
|
||||
if (new_capacity < m_capacity) memcpy(ptr, m_data, new_capacity);
|
||||
const usize new_byte_capacity = new_capacity * sizeof(T);
|
||||
|
||||
void* const ptr = TRY(realloc_impl(m_data, new_byte_capacity));
|
||||
|
||||
if (new_capacity < m_capacity) memcpy(ptr, m_data, new_byte_capacity);
|
||||
else
|
||||
memcpy(ptr, m_data, m_capacity);
|
||||
memcpy(ptr, m_data, byte_capacity());
|
||||
|
||||
m_capacity = new_capacity;
|
||||
m_data = (T*)ptr;
|
||||
return {};
|
||||
|
Loading…
Reference in New Issue
Block a user