From 8fdcd299d4dec7e6ea7d8b9f60045aefc603e9a2 Mon Sep 17 00:00:00 2001 From: Old-Ding <35417409+Old-Ding@users.noreply.github.com> Date: Mon, 6 Jul 2026 11:02:56 +0800 Subject: [PATCH] bsp: renesas: Fix LCD framebuffer bounds The Renesas LCD helper treats LCD_WIDTH and LCD_HEIGHT as pixel counts. The framebuffer clear loop and lcd_draw_pixel() accepted those count values as valid indexes, which can write one pixel past the framebuffer. Use strict bounds for the 0-based framebuffer indexes and adjust the 180-degree rotation mapping to target the last valid row and column. Generated-by: OpenAI Codex Signed-off-by: Old-Ding <35417409+Old-Ding@users.noreply.github.com> --- bsp/renesas/libraries/HAL_Drivers/drivers/drv_lcd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bsp/renesas/libraries/HAL_Drivers/drivers/drv_lcd.c b/bsp/renesas/libraries/HAL_Drivers/drivers/drv_lcd.c index 883b43d2bf7..8b77dd3c1bc 100644 --- a/bsp/renesas/libraries/HAL_Drivers/drivers/drv_lcd.c +++ b/bsp/renesas/libraries/HAL_Drivers/drivers/drv_lcd.c @@ -88,7 +88,7 @@ static void turn_on_lcd_backlight(void) static void ra_bsp_lcd_clear(uint16_t color) { - for (uint32_t i = 0; i <= LCD_BUF_SIZE / sizeof(uint16_t); i++) + for (uint32_t i = 0; i < LCD_BUF_SIZE / sizeof(uint16_t); i++) { lcd_current_working_buffer[i] = color; } @@ -97,7 +97,7 @@ static void ra_bsp_lcd_clear(uint16_t color) void lcd_draw_pixel(uint32_t x, uint32_t y, uint16_t color) { // Verify pixel is within LCD range - if ((x <= LCD_WIDTH) && (y <= LCD_HEIGHT)) + if ((x < LCD_WIDTH) && (y < LCD_HEIGHT)) { switch (screen_rotation) { @@ -108,7 +108,7 @@ void lcd_draw_pixel(uint32_t x, uint32_t y, uint16_t color) } case ROTATION_180: { - lcd_current_working_buffer[((LCD_HEIGHT - y) * LCD_WIDTH) + (LCD_WIDTH - x)] = color; + lcd_current_working_buffer[(((LCD_HEIGHT - 1) - y) * LCD_WIDTH) + ((LCD_WIDTH - 1) - x)] = color; break; } default: