dr_libs icon indicating copy to clipboard operation
dr_libs copied to clipboard

-Wstringop-overflow warnings from gcc-14

Open sezero opened this issue 9 months ago • 2 comments

Forgot reporting this here (looks like the same as https://github.com/lieff/minimp3/issues/119)

Is it bogus, or should we take it seriously?

In function 'drmp3_L3_decode_scalefactors',
    inlined from 'drmp3_L3_decode' at /tmp/SDL_sound/src/dr_mp3.h:1821:9,
    inlined from 'drmp3dec_decode_frame' at /tmp/SDL_sound/src/dr_mp3.h:2351:17:
/tmp/SDL_sound/src/dr_mp3.h:1271:42: warning: writing 2 bytes into a region of size 1 [-Wstringop-overflow=]
 1271 |             iscf[gr->n_long_sfb + i + 0] = (drmp3_uint8)(iscf[gr->n_long_sfb + i + 0] + (gr->subblock_gain[0] << sh));
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/SDL_sound/src/dr_mp3.h: In function 'drmp3dec_decode_frame':
/tmp/SDL_sound/src/dr_mp3.h:1238:30: note: at offset [39, 40] into destination object 'iscf' of size 40
 1238 |     drmp3_uint8 scf_size[4], iscf[40];
      |                              ^~~~
In function 'drmp3_L3_decode_scalefactors',
    inlined from 'drmp3_L3_decode' at /tmp/SDL_sound/src/dr_mp3.h:1821:9,
    inlined from 'drmp3dec_decode_frame' at /tmp/SDL_sound/src/dr_mp3.h:2351:17:
/tmp/SDL_sound/src/dr_mp3.h:1273:42: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
 1273 |             iscf[gr->n_long_sfb + i + 2] = (drmp3_uint8)(iscf[gr->n_long_sfb + i + 2] + (gr->subblock_gain[2] << sh));
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/SDL_sound/src/dr_mp3.h: In function 'drmp3dec_decode_frame':
/tmp/SDL_sound/src/dr_mp3.h:1238:30: note: at offset [41, 296] into destination object 'iscf' of size 40
 1238 |     drmp3_uint8 scf_size[4], iscf[40];
      |                              ^~~~

sezero avatar Mar 08 '25 16:03 sezero

I'm actually not getting that warning. I compile with -Wall -Wextra -Wpedantic, and I've tried with -Wstringop-overflow=1/2/3/4. Is there anything else I need to do enable that warning?

But looking at the messages in your post I'm honestly not sure how to take that warning. I'm quite unfamiliar with the internals of minimp3 so it's a bit hard to understand the intent without studying it further.

mackron avatar Mar 08 '25 20:03 mackron

I'm actually not getting that warning. I compile with -Wall -Wextra -Wpedantic, and I've tried with -Wstringop-overflow=1/2/3/4. Is there anything else I need to do enable that warning?

Warning shows itself at -O3 for me, not -O2. Using only -Wall as warning flags.

But looking at the messages in your post I'm honestly not sure how to take that warning. I'm quite unfamiliar with the internals of minimp3 so it's a bit hard to understand the intent without studying it further.

OK.

sezero avatar Mar 08 '25 21:03 sezero

So I'm still unable to replicate this even with -O3 -Wall. Not sure if I'm doing something wrong there, but in any case I've attempted to wrap this around a #pragma GCC diagnostic ignored "-Wstringop-overflow". Are you able to try that? It's in the master branch.

mackron avatar Jul 24 '25 20:07 mackron

The commit in master silences the warning for me.

I don't have gcc-15 yet, but I think it should be safe to change the version check from == 14 to >= 14

(It should also be safe to remove the !clang check from there, as clang advertises itself as gcc 4.2.1 as I remember, but that's just me nitpicking..)

sezero avatar Jul 24 '25 20:07 sezero

Yeah I guess I just like to keep it all locked down as tight as possible for purity sake. But you do make a fair point - I'll relax that to >= 14 so we don't have it pop up again later.

I don't mind having the clang thing there if only for the explicitness (if you reverse the condition to || defined(__clang__) it'll actually spit out a warning about an unknown warning type), but you are right there.

mackron avatar Jul 24 '25 20:07 mackron

OK, great.

You seem to have missed in relaxing gcc version check for pragma pop, though:

--- a/dr_mp3.h
+++ b/dr_mp3.h
@@ -1296,7 +1296,7 @@ static void drmp3_L3_decode_scalefactors(const drmp3_uint8 *hdr, drmp3_uint8 *is
         scf[i] = drmp3_L3_ldexp_q2(gain, iscf[i] << scf_shift);
     }
 }
-#if (defined(__GNUC__) && (__GNUC__ == 14)) && !defined(__clang__)
+#if (defined(__GNUC__) && (__GNUC__ >= 14)) && !defined(__clang__)
     #pragma GCC diagnostic pop
 #endif
 

After fixing that, this can be closed.

sezero avatar Jul 24 '25 20:07 sezero

Eh, thanks. Done.

mackron avatar Jul 24 '25 21:07 mackron