From 0946e80407150b68acd02bc59f0f3a3170142c4c Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 2 Nov 2022 00:57:17 +0100 Subject: [PATCH] esirisc_jtag: fix clang error core.VLASize The function esirisc_jtag_recv() can be called with argument num_in_fields = 0, for example as consequence of calling esirisc_jtag_continue(). In this case, num_in_bytes is zero and the allocation of the variable-length array 'r' requires size zero. src/target/esirisc_jtag.c:133:2: warning: Declared variable-length array (VLA) has zero size [core.VLASize] uint8_t r[num_in_bytes * 2]; ^~~~~~~~~ ~~~~~~~~~~~~~~~~ Fix it by forcing size one when num_in_bytes is zero. Change-Id: Id764c7b5ec4f5b3c18c7da650bbff39fc98ed049 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/7301 Tested-by: jenkins --- src/target/esirisc_jtag.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/target/esirisc_jtag.c b/src/target/esirisc_jtag.c index 54abc4003..1ec1726e5 100644 --- a/src/target/esirisc_jtag.c +++ b/src/target/esirisc_jtag.c @@ -130,7 +130,9 @@ static int esirisc_jtag_recv(struct esirisc_jtag *jtag_info, int num_in_bytes = DIV_ROUND_UP(num_in_bits, 8); struct scan_field fields[3]; - uint8_t r[num_in_bytes * 2]; + /* prevent zero-size variable length array */ + int r_size = num_in_bytes ? num_in_bytes * 2 : 1; + uint8_t r[r_size]; esirisc_jtag_set_instr(jtag_info, INSTR_DEBUG);