Skip to content

Commit 1edc2b4

Browse files
committed
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.
1 parent eff57c4 commit 1edc2b4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

locale.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4622,7 +4622,8 @@ S_toggle_locale_i(pTHX_ const locale_category_index cat_index,
46224622
"Entering toggle_locale_i: index=%d(%s)," \
46234623
" wanted=%s, actual=%s; called from %" LINE_Tf \
46244624
"\n", cat_index, category_names[cat_index],
4625-
new_locale, locale_to_restore_to, caller_line));
4625+
new_locale, locale_to_restore_to ? locale_to_restore_to : "(null)",
4626+
caller_line));
46264627

46274628
if (! locale_to_restore_to) {
46284629
locale_panic_via_(Perl_form(aTHX_

0 commit comments

Comments
 (0)