From de9e630c31bfb2c451e9ce4b257d65cb289e1afc Mon Sep 17 00:00:00 2001 From: erhan Date: Mon, 1 Feb 2021 20:47:29 +0300 Subject: [PATCH] target/esp_xtensa_apptrace: fix ub issue due to casting (char *) to (uint32 *): --- src/target/esp_xtensa_apptrace.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/target/esp_xtensa_apptrace.c b/src/target/esp_xtensa_apptrace.c index 64268f11c1..4193ce7294 100644 --- a/src/target/esp_xtensa_apptrace.c +++ b/src/target/esp_xtensa_apptrace.c @@ -462,9 +462,11 @@ static int esp_xtensa_apptrace_queue_reverse_write(struct xtensa *xtensa, uint32 } /* write full dwords */ for (uint32_t k = bsz; k >= sizeof(uint32_t); k -= sizeof(uint32_t)) { + uint32_t temp = 0; + memcpy(&temp, cur_buf - sizeof(uint32_t), sizeof(uint32_t)); res = xtensa_queue_dbg_reg_write(xtensa, NARADR_TRAXDATA, - *((uint32_t *)(void *)(cur_buf-sizeof(uint32_t)))); + temp); if (res != ERROR_OK) return res; cur_buf -= sizeof(uint32_t); @@ -546,9 +548,11 @@ static int esp_xtensa_apptrace_queue_normal_write(struct xtensa *xtensa, uint32_ } /* write full dwords */ for (uint32_t k = 0; (k+sizeof(uint32_t)) <= bsz; k += sizeof(uint32_t)) { + uint32_t temp = 0; + memcpy(&temp, cur_buf, sizeof(uint32_t)); res = xtensa_queue_dbg_reg_write(xtensa, NARADR_TRAXDATA, - *((uint32_t *)(void *)cur_buf)); + temp); if (res != ERROR_OK) return res; cur_buf += sizeof(uint32_t);