From ca6ecc4cfdab84a4968fd9444378f4f445981bc7 Mon Sep 17 00:00:00 2001 From: donmr Date: Thu, 26 Jul 2018 09:42:45 -0700 Subject: [PATCH] semihosting: Use local variable for read_result instead of *ret, and fix calculation of *ret for EOF case (#727) --- src/gdbserver/semihosting.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gdbserver/semihosting.c b/src/gdbserver/semihosting.c index 312b1517e..75fc6b1ef 100644 --- a/src/gdbserver/semihosting.c +++ b/src/gdbserver/semihosting.c @@ -307,6 +307,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { int fd; uint32_t buffer_len; void *buffer; + int read_result; if (mem_read(sl, r1, args, sizeof (args)) != 0 ) { DLOG("Semihosting SYS_READ error: " @@ -337,7 +338,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { DLOG("Semihosting: read(%d, target_addr:0x%08x, %zu)\n", fd, buffer_address, buffer_len); - *ret = (uint32_t)read(fd, buffer, buffer_len); + read_result = (uint32_t)read(fd, buffer, buffer_len); saved_errno = errno; if (*ret == (uint32_t)-1) { @@ -350,7 +351,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { *ret = buffer_len; return -1; } else { - *ret -= buffer_len; + *ret = buffer_len - read_result; } }