From da869b41fbb3bfb2c31798abf01e648d6dc15221 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Sat, 12 Dec 2020 14:09:34 +0100 Subject: Stop loading at the end of a file When section 0 is found, assume we reached the end of the serialization, so stop deserializing. --- serialize.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'serialize.c') 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(§ion, buf->data + buf->cur_pos, size); buf->handlers[section_id].fun(§ion, buf->handlers[section_id].data); buf->cur_pos += size; + return 1; } static const char sz_ident[] = "BLSTSZ\x01\x07"; -- cgit v1.2.3