On OpenBSD 7.6 I see this compiler warning:
../../../../gettext-runtime/intl/gnulib-lib/getlocalename_l-unsafe.c:337:7:
warning: comparison of nonnull parameter 'locale' equal to a null pointer is
'false' on first encounter [-Wtautological-pointer-compare]
if (locale == NULL)
^~~~~~ ~~~~
./locale.h:878:59: note: declared 'nonnull' here
_GL_FUNCDECL_RPL (duplocale, locale_t, (locale_t locale), _GL_ARG_NONNULL
((1)));
^
./locale.h:442:51: note: expanded from macro '_GL_ARG_NONNULL'
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
^
../../../../gettext-runtime/intl/gnulib-lib/getlocalename_l-unsafe.c:429:7:
warning: comparison of nonnull parameter 'locale' equal to a null pointer is
'false' on first encounter [-Wtautological-pointer-compare]
if (locale == NULL || locale == LC_GLOBAL_LOCALE)
^~~~~~ ~~~~
./locale.h:904:56: note: declared 'nonnull' here
_GL_FUNCDECL_RPL (freelocale, void, (locale_t locale), _GL_ARG_NONNULL ((1)));
^
./locale.h:442:51: note: expanded from macro '_GL_ARG_NONNULL'
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
^
Indicating that the compiler is not emitting code for the 'locale == NULL'
check.
This patch should fix it.
2025-04-24 Bruno Haible <[email protected]>
getlocalename_l-unsafe: Disable unwanted compiler optimization.
* lib/getlocalename_l-unsafe.c (_GL_ARG_NONNULL): Define to empty.
diff --git a/lib/getlocalename_l-unsafe.c b/lib/getlocalename_l-unsafe.c
index 6a72c81192..cb7ae5e5ea 100644
--- a/lib/getlocalename_l-unsafe.c
+++ b/lib/getlocalename_l-unsafe.c
@@ -14,6 +14,10 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
+/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
+ optimizes away the locale == NULL tests below. */
+#define _GL_ARG_NONNULL(params)
+
#include <config.h>
/* Specification. */