]> Savannah Git Hosting - gnulib.git/commitdiff
localename: Fix -Wtautological-pointer-compare warning in a better way.
authorBruno Haible <bruno@clisp.org>
Fri, 13 Jan 2023 22:50:21 +0000 (23:50 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 13 Jan 2023 22:50:21 +0000 (23:50 +0100)
* lib/localename.c (duplocale, freelocale): Revert last patch.
(_GL_ARG_NONNULL): Define to empty.

ChangeLog
lib/localename.c

index dc8fb2c12b96392a7589b3728955c2d21452d387..c772fc920a2d932254a45466ccdfc70f87193cc8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-01-13  Bruno Haible  <bruno@clisp.org>
+
+       localename: Fix -Wtautological-pointer-compare warning in a better way.
+       * lib/localename.c (duplocale, freelocale): Revert last patch.
+       (_GL_ARG_NONNULL): Define to empty.
+
 2023-01-13  Paul Eggert  <eggert@cs.ucla.edu>
 
        verify: work around xlclang 16.1 compiler bug
index 5a178c68fec1a1566e482772b3d18f9ec6e64d38..8fe90e0bf2fbdb288b68ecb80e1a273a13b01586 100644 (file)
 /* Native Windows code written by Tor Lillqvist <tml@iki.fi>.  */
 /* Mac OS X code written by Bruno Haible <bruno@clisp.org>.  */
 
+/* Don't use __attribute__ __nonnull__ in this compilation unit.  Otherwise gcc
+   optimizes away the locale == NULL tests below in duplocale() and freelocale(),
+   or xlclang reports -Wtautological-pointer-compare warnings for these tests.
+ */
+#define _GL_ARG_NONNULL(params)
+
 #include <config.h>
 
 /* Specification.  */
@@ -2967,6 +2973,10 @@ duplocale (locale_t locale)
   struct locale_hash_node *node;
   locale_t result;
 
+  if (locale == NULL)
+    /* Invalid argument.  */
+    abort ();
+
   node = (struct locale_hash_node *) malloc (sizeof (struct locale_hash_node));
   if (node == NULL)
     /* errno is set to ENOMEM.  */
@@ -3052,7 +3062,7 @@ void
 freelocale (locale_t locale)
 #undef freelocale
 {
-  if (locale == LC_GLOBAL_LOCALE)
+  if (locale == NULL || locale == LC_GLOBAL_LOCALE)
     /* Invalid argument.  */
     abort ();