From a58fd410d9e5dbd8a48f4796b4fd85e7bd276fff Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 31 May 2024 20:51:24 +0300
Subject: [PATCH] stb_image: silence gcc bounds-check warning (believed
erroneous)
Merge from mainstream commit: https://github.com/nothings/stb/commit/013ac3beddff3dbffafd5177e7972067cd2b5083.patch
Fixes https://github.com/libsdl-org/SDL_image/issues/453
(cherry picked from commit 900435c69669b8e60b7d565d5519b597f6c321eb)
(cherry picked from commit 89e4d058c102e3c82e870129d226de63c8503d13)
---
src/stb_image.h | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/stb_image.h b/src/stb_image.h
index 3ffd139e4..7ba9d30c9 100644
--- a/src/stb_image.h
+++ b/src/stb_image.h
@@ -1,4 +1,4 @@
-/* stb_image - v2.29 - public domain image loader - http://nothings.org/stb
+/* stb_image - v2.30 - public domain image loader - http://nothings.org/stb
no warranty implied; use at your own risk
Do this:
@@ -48,6 +48,7 @@ LICENSE
RECENT REVISION HISTORY:
+ 2.30 (2024-05-31) avoid erroneous gcc warning
2.29 (2023-05-xx) optimizations
2.28 (2023-01-29) many error fixes, security errors, just tons of stuff
2.27 (2021-07-11) document stbi_info better, 16-bit PNM support, bug fixes
@@ -5318,9 +5319,11 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp, unsigned i
// non-paletted with tRNS = constant alpha. if header-scanning, we can stop now.
if (scan == STBI__SCAN_header) { ++s->img_n; return 1; }
if (z->depth == 16) {
- for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is
+ for (k = 0; k < s->img_n && k < 3; ++k) // extra loop test to suppress false GCC warning
+ tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is
} else {
- for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger
+ for (k = 0; k < s->img_n && k < 3; ++k)
+ tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger
}
}
break;