summaryrefslogtreecommitdiff
path: root/serialize.c
diff options
context:
space:
mode:
authorAdrien Plazas <kekun.plazas@laposte.net>2020-12-12 14:09:34 +0100
committertwinaphex <libretro@gmail.com>2021-03-12 08:42:23 +0100
commitda869b41fbb3bfb2c31798abf01e648d6dc15221 (patch)
treec6ebbc4c2b5d3441032070c1b2051ab7d7cdbbbd /serialize.c
parent556e1be14b3f1647f8e07d47694c971ba5ee296e (diff)
Stop loading at the end of a file
When section 0 is found, assume we reached the end of the serialization, so stop deserializing.
Diffstat (limited to 'serialize.c')
-rw-r--r--serialize.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/serialize.c b/serialize.c
index a59151f..8c547ba 100644
--- a/serialize.c
+++ b/serialize.c
@@ -205,12 +205,15 @@ void load_buffer32(deserialize_buffer *buf, uint32_t *dst, size_t len)
}
}
-void load_section(deserialize_buffer *buf)
+int load_section(deserialize_buffer *buf)
{
if (!buf->handlers) {
fatal_error("load_section called on a deserialize_buffer with no handlers registered\n");
}
uint16_t section_id = load_int16(buf);
+ if (section_id == SECTION_END_OF_SERIALIZATION) {
+ return 0;
+ }
uint32_t size = load_int32(buf);
if (size > (buf->size - buf->cur_pos)) {
fatal_error("Section is bigger than remaining space in file");
@@ -218,12 +221,13 @@ void load_section(deserialize_buffer *buf)
if (section_id > buf->max_handler || !buf->handlers[section_id].fun) {
warning("No handler for section ID %d, save state may be from a newer version\n", section_id);
buf->cur_pos += size;
- return;
+ return 1;
}
deserialize_buffer section;
init_deserialize(&section, buf->data + buf->cur_pos, size);
buf->handlers[section_id].fun(&section, buf->handlers[section_id].data);
buf->cur_pos += size;
+ return 1;
}
static const char sz_ident[] = "BLSTSZ\x01\x07";