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

-Wmaybe-uninitialized warnings from gcc-14 #452

Closed
sezero opened this issue May 31, 2024 · 4 comments
Closed

-Wmaybe-uninitialized warnings from gcc-14 #452

sezero opened this issue May 31, 2024 · 4 comments

Comments

@sezero
Copy link
Contributor

sezero commented May 31, 2024

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
Copy link
Contributor Author

sezero commented May 31, 2024

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
Copy link
Collaborator

slouken commented May 31, 2024

Seems like a good fix, thanks!

@sezero sezero closed this as completed in b25009f May 31, 2024
sezero added a commit that referenced this issue May 31, 2024
Silences -Wmaybe-uninitialized warnings from gcc-14
Fixes #452

(cherry picked from commit b25009f)
@sezero
Copy link
Contributor Author

sezero commented May 31, 2024

Patch applied to SDL3 and SDL2 branches, and also submitted to mainstream at memononen/nanosvg#256

@slouken
Copy link
Collaborator

slouken commented May 31, 2024

Great, thanks!

slouken pushed a commit that referenced this issue Dec 13, 2024
Silences -Wmaybe-uninitialized warnings from gcc-14
Fixes #452

(cherry picked from commit b25009f)
(cherry picked from commit 69c0367)
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

2 participants