From 8132b77d612e88167e8f0c7bdc6aa9df3661fd4e Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 13 Feb 2021 23:28:16 +0100 Subject: [PATCH] stlink: swo: use completely the available buffer The buffer passed to stlink_usb_trace_read() is allocated of size *size and does not need to be zero-terminated. There is no reason to not fill its last byte. When checking the bytes available on swo, limit the retrieved byte length to *size. Change-Id: Iade0f8963118695931f13a8a3f1ab204911236b6 Signed-off-by: Antonio Borneo Reported-by: Adrian Negreanu Reviewed-on: http://openocd.zylin.com/6061 Tested-by: jenkins Reviewed-by: Adrian M Negreanu Reviewed-by: Tarek BOCHKATI --- src/jtag/drivers/stlink_usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index 73169e1e4..a5f8bdff1 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -1967,7 +1967,7 @@ static int stlink_usb_trace_read(void *handle, uint8_t *buf, size_t *size) return res; size_t bytes_avail = le_to_h_u16(h->databuf); - *size = bytes_avail < *size ? bytes_avail : *size - 1; + *size = bytes_avail < *size ? bytes_avail : *size; if (*size > 0) { res = stlink_usb_read_trace(handle, buf, *size);