Skip to content

Commit

Permalink
semihosting: Use local variable for read_result instead of *ret, and …
Browse files Browse the repository at this point in the history
…fix calculation of *ret for EOF case (stlink-org#727)
  • Loading branch information
donmr authored and xor-gate committed Jul 26, 2018
1 parent 79306cc commit ca6ecc4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/gdbserver/semihosting.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}

Expand Down

0 comments on commit ca6ecc4

Please sign in to comment.