comparison serialize.c @ 1983:a7b753e260a2 mame_interp

Merge from default
author Michael Pavone <pavone@retrodev.com>
date Sat, 09 May 2020 23:39:44 -0700
parents c3c62dbf1ceb
children
comparison
equal deleted inserted replaced
1937:cafde1255ad3 1983:a7b753e260a2
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 {