diff options
-rw-r--r-- | flash.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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; |