diff options
author | Daniel Palmer <danieruru@gmail.com> | 2014-05-20 21:37:05 +0900 |
---|---|---|
committer | Daniel Palmer <danieruru@gmail.com> | 2014-05-20 21:37:05 +0900 |
commit | eaaf0e8b84d439593a6c51309bcb7a3898dc5c5f (patch) | |
tree | 13228294ddf4de5dd642e9ee85cdaacab62b8dc1 | |
parent | 1b80869b641d15120cfb815bf880b786bd94ff29 (diff) |
Ofcourse that won't work as it'll break the CRC, so we truncate the last byte after checking the whole thing is correct
-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; |