Skip to content

Commit

Permalink
toggle_locale_i: eliminate NULL for %s format warning
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tonycoz committed Apr 15, 2024
1 parent eff57c4 commit 1edc2b4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down

0 comments on commit 1edc2b4

Please sign in to comment.