Skip to content

Commit 9aaaeb6

Browse files
committed
pp_index: Use utf8_to_bytes_new_pv
1 parent 3592498 commit 9aaaeb6

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

pp.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3824,21 +3824,29 @@ PP(pp_index)
38243824
if (little_utf8) {
38253825
/* Well, maybe instead we might be able to downgrade the small
38263826
string? */
3827-
char * const pv = (char*)bytes_from_utf8((U8 *)little_p, &llen,
3828-
&little_utf8);
3829-
if (little_utf8) {
3830-
/* If the large string is ISO-8859-1, and it's not possible to
3827+
U8 * free_little_p = NULL;
3828+
if (utf8_to_bytes_new_pv(&little_p, &llen, &free_little_p)) {
3829+
little_utf8 = false;
3830+
3831+
/* Here 'little_p' is in byte form, and 'free_little_p' is
3832+
* non-NULL if the original wasn't, and 'little_p' is pointing
3833+
* to new memory. We create a new SV for use by the rest of
3834+
* the routine that contains the new byte string, and donate it
3835+
* to temp to ensure it will get free()d */
3836+
if (free_little_p) {
3837+
little = temp = newSV_type(SVt_NULL);
3838+
sv_usepvn(temp, (char *) little_p, llen);
3839+
little_p = SvPVX_const(little);
3840+
}
3841+
}
3842+
else {
3843+
/* When the large string is ISO-8859-1, and it's not possible to
38313844
convert the small string to ISO-8859-1, then there is no
38323845
way that it could be found anywhere by index. */
38333846
retval = -1;
38343847
goto push_result;
38353848
}
38363849

3837-
/* At this point, pv is a malloc()ed string. So donate it to temp
3838-
to ensure it will get free()d */
3839-
little = temp = newSV_type(SVt_NULL);
3840-
sv_usepvn(temp, pv, llen);
3841-
little_p = SvPVX(little);
38423850
} else {
38433851
temp = newSVpvn(little_p, llen);
38443852

0 commit comments

Comments
 (0)