Skip to content

Commit 729b2ac

Browse files
committed
locale.c: Use free_me versions of byte/utf8 conversion
This simplifies the code, avoids creating a temp to be freed later, and may avoid a couple of mallocs
1 parent 76e7955 commit 729b2ac

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

locale.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8601,6 +8601,8 @@ S_strftime8(pTHX_ const char * fmt,
86018601

86028602
#endif
86038603

8604+
void * free_me = NULL;
8605+
86048606
switch (fmt_utf8ness) {
86058607
case UTF8NESS_IMMATERIAL:
86068608
break;
@@ -8619,15 +8621,12 @@ S_strftime8(pTHX_ const char * fmt,
86198621
if (! is_locale_utf8(locale)) {
86208622
locale_utf8ness = LOCALE_NOT_UTF8;
86218623

8622-
bool is_utf8 = true;
86238624
Size_t fmt_len = strlen(fmt);
8624-
fmt = (char *) bytes_from_utf8((U8 *) fmt, &fmt_len, &is_utf8);
8625-
if (is_utf8) {
8625+
if (! utf8_to_bytes_new_pv((const U8 **) &fmt, &fmt_len, &free_me))
8626+
{
86268627
SET_EINVAL;
86278628
return false;
86288629
}
8629-
8630-
SAVEFREEPV(fmt);
86318630
}
86328631
else {
86338632
locale_utf8ness = LOCALE_IS_UTF8;
@@ -8649,15 +8648,16 @@ S_strftime8(pTHX_ const char * fmt,
86498648
* locale would find any UTF-8 variant characters to be
86508649
* malformed */
86518650
Size_t fmt_len = strlen(fmt);
8652-
fmt = (char *) bytes_to_utf8((U8 *) fmt, &fmt_len);
8653-
SAVEFREEPV(fmt);
8651+
fmt = (char *) bytes_to_utf8_free_me((U8 *) fmt,
8652+
&fmt_len, &free_me);
86548653
}
86558654
}
86568655

86578656
break;
86588657
}
86598658

86608659
if (! strftime_tm(fmt, sv, locale, mytm)) {
8660+
Safefree(free_me);
86618661
return false;
86628662
}
86638663

@@ -8672,6 +8672,7 @@ S_strftime8(pTHX_ const char * fmt,
86728672
? SvPVX(sv)
86738673
:_byte_dump_string((U8 *) SvPVX(sv), SvCUR(sv) ,0)),
86748674
*result_utf8ness));
8675+
Safefree(free_me);
86758676
return true;
86768677

86778678
#undef INDEX_TO_USE

0 commit comments

Comments
 (0)