Skip to content

Commit

Permalink
Fix automatic read offset calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Koromix committed Jan 1, 2022
1 parent 1acb127 commit 807479e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/libty/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 807479e

Please sign in to comment.