diff options
author | Tim Newsome <tim@sifive.com> | 2020-07-01 08:28:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-01 08:28:27 -0700 |
commit | b50b8da476790fa5a1a0935d4837d2128a797db3 (patch) | |
tree | 90dad95be65c3d964d489c18561b2be1d1962bae | |
parent | 7a3fa1f923cf10c18d6d048ebd7679129a31eed1 (diff) | |
download | riscv-openocd-b50b8da476790fa5a1a0935d4837d2128a797db3.zip riscv-openocd-b50b8da476790fa5a1a0935d4837d2128a797db3.tar.gz riscv-openocd-b50b8da476790fa5a1a0935d4837d2128a797db3.tar.bz2 |
Warn if we are asked to read/write 0 bytes. (#492)
Technically that might be OK, but in practice it probably indicates
something went wrong somewhere. Before this change OpenOCD would crash
if it happened.
Change-Id: I2500ba67ec282915dcf2b2488f2aac9fbfdb23a3
-rw-r--r-- | src/target/riscv/riscv.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 8e7d5c7..415ba9a 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -1622,6 +1622,11 @@ static int riscv_read_phys_memory(struct target *target, target_addr_t phys_addr static int riscv_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer) { + if (count == 0) { + LOG_WARNING("0-length read from 0x%" TARGET_PRIxADDR, address); + return ERROR_OK; + } + if (riscv_select_current_hart(target) != ERROR_OK) return ERROR_FAIL; @@ -1645,6 +1650,11 @@ static int riscv_write_phys_memory(struct target *target, target_addr_t phys_add static int riscv_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer) { + if (count == 0) { + LOG_WARNING("0-length write to 0x%" TARGET_PRIxADDR, address); + return ERROR_OK; + } + if (riscv_select_current_hart(target) != ERROR_OK) return ERROR_FAIL; |