Mercurial > repos > blastem
comparison serialize.c @ 2053:3414a4423de1 segacd
Merge from default
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 15 Jan 2022 13:15:21 -0800 |
parents | c3c62dbf1ceb |
children |
comparison
equal
deleted
inserted
replaced
1692:5dacaef602a7 | 2053:3414a4423de1 |
---|---|
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 { |