Fix invalid memory usage in MemWriter

Case 1: `m_Data.size() == 0 && m_Pos == 0` => `resize` is not called.
Case 2: `size == 0` => access to `m_Data[m_Data.size()]`

Signed-off-by: Osyotr <Osyotr@users.noreply.github.com>
This commit is contained in:
Osyotr 2023-12-24 18:57:51 +03:00 committed by Viktor Govako
parent 863c755894
commit ae7027a36f

View file

@ -61,8 +61,11 @@ public:
void Write(void const * p, size_t size) override
{
if (size == 0)
return;
auto freeSize = static_cast<intptr_t>(m_Data.size() - m_Pos);
if (freeSize < 0)
if (freeSize <= 0)
{
m_Data.resize(static_cast<size_t>(m_Pos + size));
freeSize = size;