From b4c6ba0e132862b5280056d8f9d07db68c9cf5d5 Mon Sep 17 00:00:00 2001 From: Janez Date: Thu, 22 Jul 2021 15:27:20 +0200 Subject: [PATCH] Make persistent file size oversize more correct #2 --- CO_storageLinux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CO_storageLinux.c b/CO_storageLinux.c index 9f0422b..b784075 100644 --- a/CO_storageLinux.c +++ b/CO_storageLinux.c @@ -215,7 +215,7 @@ CO_ReturnError_t CO_storageLinux_init(CO_storage_t *storage, ret = CO_ERROR_DATA_CORRUPT; } else { - buf = malloc(entry->len + 4); + buf = malloc(entry->len + sizeof(uint16_t)); if (buf == NULL) { fclose(fp); *storageInitError = i; @@ -225,7 +225,7 @@ CO_ReturnError_t CO_storageLinux_init(CO_storage_t *storage, /* Read data into temporary buffer first. Then verify and copy to addr*/ if (!dataCorrupt) { - size_t cnt = fread(buf, 1, entry->len + 4, fp); + size_t cnt = fread(buf, 1, entry->len + sizeof(uint16_t), fp); /* If file is empty, just skip loading, default values will be used, * no error. Otherwise verify length and crc and copy data. */