From 29081ab19b21fb79085086fed3d665092e423ee4 Mon Sep 17 00:00:00 2001 From: xuxingliang Date: Tue, 10 Dec 2024 15:24:36 +0800 Subject: [PATCH] system/coredump: fix core file size mismatch Write exactly the same data size to core file. Signed-off-by: xuxingliang --- system/coredump/coredump.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/system/coredump/coredump.c b/system/coredump/coredump.c index 8bb1a4a2f..d9f8994e7 100644 --- a/system/coredump/coredump.c +++ b/system/coredump/coredump.c @@ -240,7 +240,13 @@ static void coredump_restore(FAR char *savepath, size_t maxfile) lseek(blkfd, 0, SEEK_SET); while (offset < info.size) { - readsize = read(blkfd, swap, CONFIG_SYSTEM_COREDUMP_SWAPBUFFER_SIZE); + readsize = info.size - offset; + if (readsize > CONFIG_SYSTEM_COREDUMP_SWAPBUFFER_SIZE) + { + readsize = CONFIG_SYSTEM_COREDUMP_SWAPBUFFER_SIZE; + } + + readsize = read(blkfd, swap, readsize); if (readsize < 0) { printf("Read %s fail\n", CONFIG_SYSTEM_COREDUMP_DEVPATH);