From 2bbe375c3472711873d1473a7f5911cfc6e22101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Sun, 15 Nov 2026 09:51:31 -0800 Subject: [PATCH] Fixed HDR decoding miscompiled by GCC 15. Fixes #152. --- 3rdparty/stb/stb_image.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/3rdparty/stb/stb_image.h b/3rdparty/stb/stb_image.h index c1a396d5..0f693061 100644 --- a/3rdparty/stb/stb_image.h +++ b/3rdparty/stb/stb_image.h @@ -7155,6 +7155,16 @@ static void stbi__hdr_convert(float *output, stbi_uc *input, int req_comp) } } +static void stbi__hdr_load_flat(stbi__context *s, float *hdr_data, int start, int num, int req_comp) +{ + int i; + for (i=start; i < num; ++i) { + stbi_uc rgbe[4]; + stbi__getn(s, rgbe, 4); + stbi__hdr_convert(hdr_data + i * req_comp, rgbe, req_comp); + } +} + static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) { char buffer[STBI__HDR_BUFLEN]; @@ -7215,14 +7225,7 @@ static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int re // image data is stored as some number of sca if ( width < 8 || width >= 32768) { // Read flat data - for (j=0; j < height; ++j) { - for (i=0; i < width; ++i) { - stbi_uc rgbe[4]; - main_decode_loop: - stbi__getn(s, rgbe, 4); - stbi__hdr_convert(hdr_data + j * width * req_comp + i * req_comp, rgbe, req_comp); - } - } + stbi__hdr_load_flat(s, hdr_data, 0, width * height, req_comp); } else { // Read RLE-encoded data scanline = NULL; @@ -7240,10 +7243,9 @@ static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int re rgbe[2] = (stbi_uc) len; rgbe[3] = (stbi_uc) stbi__get8(s); stbi__hdr_convert(hdr_data, rgbe, req_comp); - i = 1; - j = 0; STBI_FREE(scanline); - goto main_decode_loop; // yes, this makes no sense + stbi__hdr_load_flat(s, hdr_data, 1, width * height, req_comp); + return hdr_data; } len <<= 8; len |= stbi__get8(s);