comparison 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
comparison
equal deleted inserted replaced
1945:ba7231d2411c 1946:c3c62dbf1ceb
18 } 18 }
19 19
20 static void reserve(serialize_buffer *buf, size_t amount) 20 static void reserve(serialize_buffer *buf, size_t amount)
21 { 21 {
22 if (amount > (buf->storage - buf->size)) { 22 if (amount > (buf->storage - buf->size)) {
23 buf->storage *= 2; 23 if (amount < buf->storage) {
24 buf = realloc(buf, buf->storage + sizeof(*buf)); 24 buf->storage *= 2;
25 } else {
26 //doublign isn't enough, increase by the precise amount needed
27 buf->storage += amount - (buf->storage - buf->size);
28 }
29 buf->data = realloc(buf->data, buf->storage + sizeof(*buf));
25 } 30 }
26 } 31 }
27 32
28 void save_int32(serialize_buffer *buf, uint32_t val) 33 void save_int32(serialize_buffer *buf, uint32_t val)
29 { 34 {