From b50b8da476790fa5a1a0935d4837d2128a797db3 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Wed, 1 Jul 2020 08:28:27 -0700 Subject: [PATCH] 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 --- src/target/riscv/riscv.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 8e7d5c7d3..415ba9abf 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;