Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array Out Of Bounds - stb_image_resize2.h #1616

Open
ThatOSDev opened this issue Feb 27, 2024 · 6 comments
Open

Array Out Of Bounds - stb_image_resize2.h #1616

ThatOSDev opened this issue Feb 27, 2024 · 6 comments

Comments

@ThatOSDev
Copy link

ThatOSDev commented Feb 27, 2024

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.

@nothings
Copy link
Owner

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.

@ThatOSDev
Copy link
Author

ThatOSDev commented Feb 29, 2024

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

@jeffrbig2
Copy link

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.

@ThatOSDev
Copy link
Author

ThatOSDev commented Mar 1, 2024

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.

@jeffrbig2
Copy link

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...

@ThatOSDev
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants