summaryrefslogtreecommitdiff
path: root/flash.c
diff options
context:
space:
mode:
Diffstat (limited to 'flash.c')
-rw-r--r--flash.c5
1 files 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;