From eaaf0e8b84d439593a6c51309bcb7a3898dc5c5f Mon Sep 17 00:00:00 2001 From: Daniel Palmer Date: Tue, 20 May 2014 21:37:05 +0900 Subject: Ofcourse that won't work as it'll break the CRC, so we truncate the last byte after checking the whole thing is correct --- flash.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flash.c b/flash.c index 57f8fc0..48470bb 100644 --- a/flash.c +++ b/flash.c @@ -235,6 +235,7 @@ bool persistence_freeze(char* dest, void* data, unsigned int offset, unsigned in bool persistence_unfreeze(char* dest, void* result, unsigned int len, uint32_t version) { + bool truncatelastbyte = false; int fd = open(dest, O_RDONLY); // get the header @@ -253,7 +254,7 @@ bool persistence_unfreeze(char* dest, void* result, unsigned int len, uint32_t v #if FROZENSMALLEROK if (hdr.length < len) { printf("frozen struct is %d bytes smaller than the requested size, removing end byte\n", len - hdr.length); - hdr.length -= 1; + truncatelastbyte = true; goto hdrlengthok; } #endif @@ -298,7 +299,7 @@ hdrlengthok: } close(fd); - memcpy(result, tempresult, MIN(len, hdr.length)); + memcpy(result, tempresult, MIN(len, truncatelastbyte ? (hdr.length - 1) : hdr.length)); g_free(tempresult); return true; -- cgit