From 3248616fa5a7004c86ff2d4acf4718ee28cb7630 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 13 Jan 2023 23:50:21 +0100 Subject: [PATCH] localename: Fix -Wtautological-pointer-compare warning in a better way. * lib/localename.c (duplocale, freelocale): Revert last patch. (_GL_ARG_NONNULL): Define to empty. --- ChangeLog | 6 ++++++ lib/localename.c | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index dc8fb2c12b..c772fc920a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-01-13 Bruno Haible + + 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 verify: work around xlclang 16.1 compiler bug diff --git a/lib/localename.c b/lib/localename.c index 5a178c68fe..8fe90e0bf2 100644 --- a/lib/localename.c +++ b/lib/localename.c @@ -18,6 +18,12 @@ /* Native Windows code written by Tor Lillqvist . */ /* Mac OS X code written by Bruno Haible . */ +/* 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 /* 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 (); -- 2.39.5