From 4a70ac674e4131e9f5ce56aa3666e15b7b20867a Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sat, 12 Oct 2024 08:23:10 -0600 Subject: [PATCH] locale.c: Use new utf8_to_bytes_temp_pv() --- locale.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/locale.c b/locale.c index 2820cd2a4b36..5bd504d3e642 100644 --- a/locale.c +++ b/locale.c @@ -8619,15 +8619,11 @@ S_strftime8(pTHX_ const char * fmt, if (! is_locale_utf8(locale)) { locale_utf8ness = LOCALE_NOT_UTF8; - bool is_utf8 = true; Size_t fmt_len = strlen(fmt); - fmt = (char *) bytes_from_utf8((U8 *) fmt, &fmt_len, &is_utf8); - if (is_utf8) { + if (! utf8_to_bytes_temp_pv((U8 **) &fmt, &fmt_len)) { SET_EINVAL; return false; } - - SAVEFREEPV(fmt); } else { locale_utf8ness = LOCALE_IS_UTF8; @@ -9839,14 +9835,12 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string, } else { /* locale is not UTF-8; but input is; downgrade the input */ - s = (char *) bytes_from_utf8((const U8 *) s, &len, &utf8); - - /* If the downgrade was successful we are done, but if the input - * contains things that require UTF-8 to represent, have to do - * damage control ... */ - if (UNLIKELY(utf8)) { - - /* What we do is construct a non-UTF-8 string with + if (UNLIKELY(! utf8_to_bytes_temp_pv((const U8 **) &s, &len))) { + /* If the downgrade was successful we are done, but if the + * input contains things that require UTF-8 to represent, have + * to do damage control: + * + * What we do is construct a non-UTF-8 string with * 1) the characters representable by a single byte converted * to be so (if necessary); * 2) and the rest converted to collate the same as the @@ -9866,8 +9860,6 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string, * sort entirely equal, then the sort order for the * above-255 code points will be in code point order. */ - utf8 = FALSE; - /* If we haven't calculated the code point with the maximum * collating order for this locale, do so now */ if (! PL_strxfrm_max_cp) { @@ -9957,6 +9949,8 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string, Renew(s, d, char); /* Free up unused space */ } } + + utf8 = false; } /* Here, we have constructed a modified version of the input. It could