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 <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7301
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2022-11-02 00:57:17 +01:00
parent 7a09635735
commit 0946e80407
1 changed files with 3 additions and 1 deletions

View File

@ -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); int num_in_bytes = DIV_ROUND_UP(num_in_bits, 8);
struct scan_field fields[3]; 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); esirisc_jtag_set_instr(jtag_info, INSTR_DEBUG);