From 16fa57da41d3db444609a94e141e815ab1f6513b Mon Sep 17 00:00:00 2001 From: Tommy Murphy Date: Wed, 2 Oct 2024 21:08:24 +0100 Subject: [PATCH] Fix riscv013_invalidate_cached_progbuf() off by one error See https://github.com/riscv-collab/riscv-openocd/issues/1139 riscv013_invalidate_cached_progbuf() was failing to zeroize the final buffer array element. Use memset() instead of a manual loop to zeroize it in order to address this and simplify the code. --- src/target/riscv/riscv-013.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index bb4c9289f..7bef955e5 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -5282,8 +5282,7 @@ static int riscv013_invalidate_cached_progbuf(struct target *target) } LOG_TARGET_DEBUG(target, "Invalidating progbuf cache"); - for (unsigned int i = 0; i < 15; i++) - dm->progbuf_cache[i] = 0; + memset(dm->progbuf_cache, 0, sizeof(dm->progbuf_cache)); return ERROR_OK; }