Mercurial > repos > blastem
diff serialize.c @ 1946:c3c62dbf1ceb
WIP netplay support
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 29 Apr 2020 01:00:57 -0700 |
parents | 2540c05520f2 |
children |
line wrap: on
line diff
--- a/serialize.c Wed Apr 29 01:00:15 2020 -0700 +++ b/serialize.c Wed Apr 29 01:00:57 2020 -0700 @@ -20,8 +20,13 @@ static void reserve(serialize_buffer *buf, size_t amount) { if (amount > (buf->storage - buf->size)) { - buf->storage *= 2; - buf = realloc(buf, buf->storage + sizeof(*buf)); + if (amount < buf->storage) { + buf->storage *= 2; + } else { + //doublign isn't enough, increase by the precise amount needed + buf->storage += amount - (buf->storage - buf->size); + } + buf->data = realloc(buf->data, buf->storage + sizeof(*buf)); } }