libsdl-org / SDL_image

Image decoding for many popular formats for Simple Directmedia Layer.
zlib License
513 stars 174 forks source link

-Wmaybe-uninitialized warnings from gcc-14 #452

Closed sezero closed 1 month ago

sezero commented 1 month ago

As inlined below

In file included from /tmp/SDL_image/src/IMG_svg.c:83:
In function 'nsvg__xformMultiply',
    inlined from 'nsvg__xformPremultiply' at /tmp/SDL_image/src/nanosvg.h:554:2,
    inlined from 'nsvg__parseTransform' at /tmp/SDL_image/src/nanosvg.h:1717:3:
/tmp/SDL_image/src/nanosvg.h:523:25: warning: 't[0]' may be used uninitialized [-Wmaybe-uninitialized]
  523 |         float t0 = t[0] * s[0] + t[1] * s[2];
      |                    ~~~~~^~~~~~
/tmp/SDL_image/src/nanosvg.h: In function 'nsvg__parseTransform':
/tmp/SDL_image/src/nanosvg.h:1689:15: note: 't[0]' was declared here
 1689 |         float t[6];
      |               ^
In function 'nsvg__xformMultiply',
    inlined from 'nsvg__xformPremultiply' at /tmp/SDL_image/src/nanosvg.h:554:2,
    inlined from 'nsvg__parseTransform' at /tmp/SDL_image/src/nanosvg.h:1717:3:
/tmp/SDL_image/src/nanosvg.h:523:39: warning: 't[1]' may be used uninitialized [-Wmaybe-uninitialized]
  523 |         float t0 = t[0] * s[0] + t[1] * s[2];
      |                                  ~~~~~^~~~~~
/tmp/SDL_image/src/nanosvg.h: In function 'nsvg__parseTransform':
/tmp/SDL_image/src/nanosvg.h:1689:15: note: 't[1]' was declared here
 1689 |         float t[6];
      |               ^
In function 'nsvg__xformMultiply',
    inlined from 'nsvg__xformPremultiply' at /tmp/SDL_image/src/nanosvg.h:554:2,
    inlined from 'nsvg__parseTransform' at /tmp/SDL_image/src/nanosvg.h:1717:3:
/tmp/SDL_image/src/nanosvg.h:527:21: warning: 't[2]' may be used uninitialized [-Wmaybe-uninitialized]
  527 |         t[3] = t[2] * s[1] + t[3] * s[3];
      |                ~~~~~^~~~~~
/tmp/SDL_image/src/nanosvg.h: In function 'nsvg__parseTransform':
/tmp/SDL_image/src/nanosvg.h:1689:15: note: 't[2]' was declared here
 1689 |         float t[6];
      |               ^
In function 'nsvg__xformMultiply',
    inlined from 'nsvg__xformPremultiply' at /tmp/SDL_image/src/nanosvg.h:554:2,
    inlined from 'nsvg__parseTransform' at /tmp/SDL_image/src/nanosvg.h:1717:3:
/tmp/SDL_image/src/nanosvg.h:527:35: warning: 't[3]' may be used uninitialized [-Wmaybe-uninitialized]
  527 |         t[3] = t[2] * s[1] + t[3] * s[3];
      |                              ~~~~~^~~~~~
/tmp/SDL_image/src/nanosvg.h: In function 'nsvg__parseTransform':
/tmp/SDL_image/src/nanosvg.h:1689:15: note: 't[3]' was declared here
 1689 |         float t[6];
      |               ^
In function 'nsvg__xformMultiply',
    inlined from 'nsvg__xformPremultiply' at /tmp/SDL_image/src/nanosvg.h:554:2,
    inlined from 'nsvg__parseTransform' at /tmp/SDL_image/src/nanosvg.h:1717:3:
/tmp/SDL_image/src/nanosvg.h:528:21: warning: 't[4]' may be used uninitialized [-Wmaybe-uninitialized]
  528 |         t[5] = t[4] * s[1] + t[5] * s[3] + s[5];
      |                ~~~~~^~~~~~
/tmp/SDL_image/src/nanosvg.h: In function 'nsvg__parseTransform':
/tmp/SDL_image/src/nanosvg.h:1689:15: note: 't[4]' was declared here
 1689 |         float t[6];
      |               ^
In function 'nsvg__xformMultiply',
    inlined from 'nsvg__xformPremultiply' at /tmp/SDL_image/src/nanosvg.h:554:2,
    inlined from 'nsvg__parseTransform' at /tmp/SDL_image/src/nanosvg.h:1717:3:
/tmp/SDL_image/src/nanosvg.h:528:35: warning: 't[5]' may be used uninitialized [-Wmaybe-uninitialized]
  528 |         t[5] = t[4] * s[1] + t[5] * s[3] + s[5];
      |                              ~~~~~^~~~~~
/tmp/SDL_image/src/nanosvg.h: In function 'nsvg__parseTransform':
/tmp/SDL_image/src/nanosvg.h:1689:15: note: 't[5]' was declared here
 1689 |         float t[6];
      |               ^
sezero commented 1 month ago

The following one-liner silences it for me: Is it good or may there be any subtleties I'm missing?

diff --git a/src/nanosvg.h b/src/nanosvg.h
index 14bbcf4..64d05d6 100644
--- a/src/nanosvg.h
+++ b/src/nanosvg.h
@@ -1686,7 +1686,7 @@ static int nsvg__parseRotate(float* xform, const char* str)

 static void nsvg__parseTransform(float* xform, const char* str)
 {
-   float t[6];
+   float t[6] = { 0 };
    int len;
    nsvg__xformIdentity(xform);
    while (*str)
slouken commented 1 month ago

Seems like a good fix, thanks!

sezero commented 1 month ago

Patch applied to SDL3 and SDL2 branches, and also submitted to mainstream at https://github.com/memononen/nanosvg/pull/256

slouken commented 1 month ago

Great, thanks!