From 1edc2b4ee3077fc72d6364edfe0281ea10aab252 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Mon, 8 Apr 2024 14:03:38 +1000 Subject: [PATCH] toggle_locale_i: eliminate NULL for %s format warning The C99 printf() family of functions do not permit a NULL pointer for the %s format specifier. In this case, there's a NULL check done immediately afterwards, allowing the compiler to detect that locale_to_restore_to could be NULL. While PerlIO_printf() (via sv_vcatpvfn_flags()) does allow NULL, it isn't permitted by the standard implementation, so gcc warns. Ideally the compiler would provide customisation hooks for this warning, but it doesn't, and since the -Wformat family of warnings are useful, do the minimal change to prevent it in this case. --- locale.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/locale.c b/locale.c index 6f479d90385c..e4dafaff787b 100644 --- a/locale.c +++ b/locale.c @@ -4622,7 +4622,8 @@ S_toggle_locale_i(pTHX_ const locale_category_index cat_index, "Entering toggle_locale_i: index=%d(%s)," \ " wanted=%s, actual=%s; called from %" LINE_Tf \ "\n", cat_index, category_names[cat_index], - new_locale, locale_to_restore_to, caller_line)); + new_locale, locale_to_restore_to ? locale_to_restore_to : "(null)", + caller_line)); if (! locale_to_restore_to) { locale_panic_via_(Perl_form(aTHX_