MemoryWriter: Use a std::unique_ptr within resize()

Same behavior, but keeps the memory managed throughout its whole
lifetime.
This commit is contained in:
Lioncash 2019-09-06 03:28:29 -04:00
parent 57ad780321
commit de45f0896f
1 changed files with 6 additions and 7 deletions

View File

@ -260,15 +260,14 @@ void MemoryCopyWriter::resize(atUint64 newSize) {
}
// Allocate and copy new buffer
atUint8* newArray = new atUint8[newSize];
memset(newArray, 0, newSize);
if (m_dataCopy)
memmove(newArray, m_dataCopy.get(), m_length);
m_dataCopy.reset(newArray);
auto newArray = std::make_unique<atUint8[]>(newSize);
if (m_dataCopy) {
std::memmove(newArray.get(), m_dataCopy.get(), m_length);
}
m_dataCopy = std::move(newArray);
// Swap the pointer and size out for the new ones.
m_data = newArray;
m_data = m_dataCopy.get();
m_length = newSize;
}