stb
stb copied to clipboard
Array Out Of Bounds - stb_image_resize2.h
Describe the bug Lines 8510, 8611, and 8702 show the same code used, and each line causes an Out Of Bounds warning in GCC 11.2. The filename is stb_image_resize2.h GCC 11.2 with c17.
stbir_uint32 const * to_srgb = fp32_to_srgb8_tab4 - (127-13)*8;
It will SPAM you with the same array warning for each one of the three lines listed above. This below is just one of hundreds of spam-like examples of the warning.
libs\raylib-master\src\external\stb_image_resize2.h|1129|note: while referencing 'fp32_to_srgb8_tab4'|
libs\raylib-master\src\external\stb_image_resize2.h|8702|warning: array subscript -912 is outside array bounds of 'stbir_uint32[104]' {aka 'unsigned int[104]'} [-Warray-bounds]|
I edited the beginning of the path to libs / raylib to keep it simpler to read. However, this is not about raylib, but about the warning generated from stb_image_resize2.h.
SIDE NOTE : I have tested this in the new raylib 5.0. It's using the same file (stb_image_resize2.h) from the original stb github. So you can easily reproduce this warning by compiling the raylib code if that makes it easier to spot. The warning always comes from those lines in stb_image_resize2.h.
As far as I can tell, you have to enable this warning explicitly, or use -Wall. We don't generally fix -Wall-only warnings.
Because you're meant to compile the project into your source code with your own compiler settings, we do try to eliminate warnings in general, but warnings from -Wall are generally too numerous, too marginal, or too inconsistent.
As far as I can tell, you have to enable this warning explicitly, or use
-Wall. We don't generally fix-Wall-only warnings.
--SNIP--
I should have added my settings... Here is what I use in my makefile.
CFLAGS=-Wall -Werror -std=c17 -m64 -O2
From what I am seeing, the function is trying to run math on an array table "fp32_to_srgb8_tab4". And this is why it's showing an Out Of Bounds warning.
I did succeed in removing the warning once, when I removed the const pointer. (I'm overly simplifying how I did it, but you get the idea.) However, I'm not sure if that was the right thing to do. Either way, I was told to mention this warning here from the raylib discord, since raylib 5.0 is using the stb_image_resize2.h header file. In raylib 4.x it was using the first iteration "stb_image_resize.h". It was fine with no errors. But version 2 seems to have a lot of issues. I only listed just one of them here on this thread.
I'll post if I find a fix for this. Thanks for replying. Cheers
I can post a fix for this one - like Sean said we don't normally worry about -Wall, but I can tweak the code easily enough to avoid the GCC warning easily enough. It does not read outside the buffer, of course - it's just an, in this case, unhelpful warning.
I can post a fix for this one - like Sean said we don't normally worry about -Wall, but I can tweak the code easily enough to avoid the GCC warning easily enough. It does not read outside the buffer, of course - it's just an, in this case, unhelpful warning.
That would be great Jeff. Thank you.
Side Note : If this was one or two warnings, I wouldn't bother you all with it. But this spams 144 Warnings all for that same thing. So the Fix will be MUCH appreciated. Cheers.
No prob!
Remember you can do:
#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" #include "stb_image_resize2.h" #pragma GCC diagnostic pop
In the meantime...
No prob!
Remember you can do:
#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" #include "stb_image_resize2.h" #pragma GCC diagnostic pop
In the meantime...
That supression trick comes in handy. Thank you for the feedback. Cheers
Hi all,
I just wanted to add that this same warning has caused us some trouble as well in OpenUSD. If anyone has a fix already, it would be great to see that merged, or at least I could add it as a patch in my build.
Thanks!
I just posted the next version that fixes this, but remember you can easily wrap the header to avoid this (see two messages above)...
I just posted the next version that fixes this, but remember you can easily wrap the header to avoid this (see two messages above)...
Found your pull request. I'll keep my eyes out. THANK YOU !!!!
I have merged Jeff's new version to the repo. Looking at the code I'm not sure that this fixes the warning, let me know if it doesn't and I'll reopen.
I may still have to roll the negative into the index, but this silenced on my mingw...
Works great for me. Thanks so much!