]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Avoid gcc -Wformat-security warnings with --disable-nls.
authorBruno Haible <bruno@clisp.org>
Wed, 28 May 2025 14:50:19 +0000 (16:50 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 28 May 2025 14:50:19 +0000 (16:50 +0200)
Reported by Holger Hoffstätte <holger@applied-asynchrony.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-05/msg00225.html>.

* gnulib-local/lib/gettext.h (gettext, dgettext, dcgettext): With gcc in C mode,
define these as inline functions.

gnulib-local/lib/gettext.h

index e07880bb3d5e8a658b66acf511899bab970aa073..6d3ffa7078f8d82b1fc314fc945af665d9ee0a3f 100644 (file)
@@ -1,5 +1,5 @@
 /* Convenience header for conditional use of GNU <libintl.h>.
-   Copyright (C) 1995-2024 Free Software Foundation, Inc.
+   Copyright (C) 1995-2025 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
 #  endif
 # endif
 
-/* Disabled NLS.
-   The casts to 'const char *' serve the purpose of producing warnings
-   for invalid uses of the value returned from these functions.
-   On pre-ANSI systems without 'const', the config.h file is supposed to
-   contain "#define const".  */
-# undef gettext
-# define gettext(Msgid) ((const char *) (Msgid))
-# undef dgettext
-# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
-# undef dcgettext
-# define dcgettext(Domainname, Msgid, Category) \
-    ((void) (Category), dgettext (Domainname, Msgid))
+/* Disabled NLS.  */
+# if defined __GNUC__ && !defined __clang__ && !defined __cplusplus
+/* Use inline functions, to avoid warnings
+     warning: format not a string literal and no format arguments
+   that don't occur with enabled NLS.  */
+__attribute__ ((__always_inline__, __gnu_inline__)) extern inline
+const char *
+gettext (const char *msgid)
+{
+  return msgid;
+}
+__attribute__ ((__always_inline__, __gnu_inline__)) extern inline
+const char *
+dgettext (const char *domain, const char *msgid)
+{
+  (void) domain;
+  return msgid;
+}
+__attribute__ ((__always_inline__, __gnu_inline__)) extern inline
+const char *
+dcgettext (const char *domain, const char *msgid, int category)
+{
+  (void) domain;
+  (void) category;
+  return msgid;
+}
+# else
+/* The casts to 'const char *' serve the purpose of producing warnings
+   for invalid uses of the value returned from these functions.  */
+#  undef gettext
+#  define gettext(Msgid) ((const char *) (Msgid))
+#  undef dgettext
+#  define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
+#  undef dcgettext
+#  define dcgettext(Domainname, Msgid, Category) \
+     ((void) (Category), dgettext (Domainname, Msgid))
+# endif
 # undef ngettext
 # define ngettext(Msgid1, Msgid2, N) \
     ((N) == 1 \