From 807479eed0b2d1586b7d1b61eec1e3f9563ef666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Martign=C3=A8ne?= Date: Sat, 1 Jan 2022 07:31:17 +0100 Subject: [PATCH] Fix automatic read offset calculation --- src/libty/firmware.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libty/firmware.c b/src/libty/firmware.c index 9c193c1..75ead3a 100644 --- a/src/libty/firmware.c +++ b/src/libty/firmware.c @@ -140,6 +140,8 @@ static ssize_t read_file(int64_t offset, uint8_t *buf, size_t len, void *udata) return ty_error(TY_ERROR_SYSTEM, "fseek('%s') failed: %s", ctx->filename, strerror(errno)); } } + + ctx->offset = offset; } r = (ssize_t)fread(buf, 1, len, ctx->fp); @@ -166,7 +168,7 @@ static ssize_t read_memory(int64_t offset, uint8_t *buf, size_t len, void *udata size_t copy_len = _HS_MIN((size_t)ctx->len - (size_t)offset, (size_t)len); memcpy(buf, ctx->mem + offset, copy_len); - ctx->offset += (int64_t)copy_len; + ctx->offset = offset + (int64_t)copy_len; return (ssize_t)copy_len; }