RFR: 8355077: Compiler error at splashscreen_gif.c due to unterminated string initialization

Yasumasa Suenaga ysuenaga at openjdk.org
Wed Apr 23 01:07:49 UTC 2025


On Sun, 20 Apr 2025 02:16:50 GMT, Yasumasa Suenaga <ysuenaga at openjdk.org> wrote:

> I tried to build OpenJDK with GCC 15.0.1 on Fedora 42 x86_64, however I saw following error.
> 
> 
> * For target support_native_java.desktop_libsplashscreen_splashscreen_gif.o:
> /home/ysuenaga/github-forked/jdk/src/java.desktop/share/native/libsplashscreen/splashscreen_gif.c:51:41: error: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (12 chars into 11 available) [-Werror=unterminated-string-initialization]
>    51 | static const char szNetscape20ext[11] = "NETSCAPE2.0";
>       | ^~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> 
> 
> This constant seems to be used to detect Netscape 2.0 extension in GIF image. It should be used to compare with extension block without NUL char, but we should tweak initialization to avoid this error for safety code.

I think this behavior is not a bug in GCC.

`splashscreen_gif.c` would be compiled with `-Wextra`, then `-Wunterminated-string-initialization` is enabled by default, then the warning would be reported as I shown.  
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wunterminated-string-initialization

As an option, we can set `nonstring` attribute as following. Similar use case in Linux Kernel has introduced in [GCC bugzilla](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178). Is this more suitable in this case? 


diff --git a/src/java.desktop/share/native/libsplashscreen/splashscreen_gif.c b/src/java.desktop/share/native/libsplashscreen/splashscreen_gif.c
index 3654c677493..047f08835ad 100644
--- a/src/java.desktop/share/native/libsplashscreen/splashscreen_gif.c
+++ b/src/java.desktop/share/native/libsplashscreen/splashscreen_gif.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -48,7 +48,7 @@
                                 // restore the area overwritten by the graphic with
                                 // what was there prior to rendering the graphic.

-static const char szNetscape20ext[11] = "NETSCAPE2.0";
+static const char szNetscape20ext[11] __attribute__((nonstring)) = "NETSCAPE2.0";

 #define NSEXT_LOOP      0x01    // Loop Count field code

-------------

PR Comment: https://git.openjdk.org/jdk/pull/24770#issuecomment-2822812782


More information about the client-libs-dev mailing list