From a27d49b6f2d3310855d2e52bd1d320b6040bb4c6 Mon Sep 17 00:00:00 2001 From: pstef <3462925+pstef@users.noreply.github.com> Date: Wed, 19 Mar 2025 19:57:50 +0000 Subject: [PATCH] Silence GCC stringop-overflow At optimization level -O3, GCC generates a warning about its own optimizations, likely due to loop unrolling. Manually unroll the loop to eliminate any ambiguity and prevent the warning. --- libretro-common/formats/tga/rtga.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libretro-common/formats/tga/rtga.c b/libretro-common/formats/tga/rtga.c index 01b96e35a5..ec9c1846b5 100644 --- a/libretro-common/formats/tga/rtga.c +++ b/libretro-common/formats/tga/rtga.c @@ -265,9 +265,7 @@ static uint8_t *rtga_tga_load(rtga_context *s, int RLE_repeating = 0; int RLE_count = 0; int read_next_pixel = 1; - /* Needs to be at least 33 bytes to silence a GCC warning, - * only 4 are actually used */ - unsigned char raw_data[33] = {0}; + unsigned char raw_data[4] = {0}; unsigned char *tga_palette = NULL; /* Do I need to load a palette? */ @@ -337,8 +335,14 @@ static uint8_t *rtga_tga_load(rtga_context *s, else { /* read in the data raw */ - for (j = 0; j*8 < tga_bits_per_pixel; ++j) - raw_data[j] = rtga_get8(s); + /* manually unroll, probably GCC bug 92955 */ + j = 0; + switch (tga_bits_per_pixel) { + case 32: raw_data[j++] = rtga_get8(s); /* fallthrough */ + case 24: raw_data[j++] = rtga_get8(s); /* fallthrough */ + case 16: raw_data[j++] = rtga_get8(s); /* fallthrough */ + case 8: raw_data[j++] = rtga_get8(s); + } } /* clear the reading flag for the next pixel */