From f9feb2e74dd355fde030a2d935ab2e53c3e02e81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20=C3=85gren?= Date: Tue, 17 Sep 2024 13:36:39 +0200 Subject: [PATCH] Wrap accesses to UART output buffers --- hw/usb_interface/ch552_fw/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/usb_interface/ch552_fw/main.c b/hw/usb_interface/ch552_fw/main.c index f12925f..9cbf178 100644 --- a/hw/usb_interface/ch552_fw/main.c +++ b/hw/usb_interface/ch552_fw/main.c @@ -997,19 +997,19 @@ void main() FrameMode = UartRxBuf[UartRxBufOutputPointer]; // Extract frame mode if ((FrameMode == MODE_CDC) || (FrameMode == MODE_HID)) { - FrameLength = UartRxBuf[UartRxBufOutputPointer + 1]; // Extract frame length + FrameLength = UartRxBuf[increment_pointer(UartRxBufOutputPointer, 1, UART_RX_BUF_SIZE)]; // Extract frame length FrameStarted = 1; } else { // Invalid mode if (!Halted) { printStr("Invalid header: 0x"); printNumHex(FrameMode); printStr(", len = "); - printNumU32(UartRxBuf[UartRxBufOutputPointer + 1]); + printNumU32(UartRxBuf[increment_pointer(UartRxBufOutputPointer, 1, UART_RX_BUF_SIZE)]); printStr("\n"); uint16_t i; uint8_t print_char_count_out = 0; for (i=0; i= 16) { printStr("\n"); @@ -1040,7 +1040,7 @@ void main() if (FrameStarted) { // Check if a complete frame has been received, include one mode byte and and one length byte if (UartRxBufByteCount >= (FrameLength + 2)) { - UartRxBufOutputPointer+=2; // Start at valid data so skip the mode and length byte + UartRxBufOutputPointer = increment_pointer(UartRxBufOutputPointer, 2, UART_RX_BUF_SIZE); // Start at valid data so skip the mode and length byte if (FrameMode == MODE_CDC) { circular_copy(CdcRxBuf + CdcRxBufLength, UartRxBuf,