Skip to content

Commit

Permalink
pp_index: Use utf8_to_bytes_new_pv
Browse files Browse the repository at this point in the history
  • Loading branch information
khwilliamson committed Dec 4, 2024
1 parent 3592498 commit 9aaaeb6
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3824,21 +3824,29 @@ PP(pp_index)
if (little_utf8) {
/* Well, maybe instead we might be able to downgrade the small
string? */
char * const pv = (char*)bytes_from_utf8((U8 *)little_p, &llen,
&little_utf8);
if (little_utf8) {
/* If the large string is ISO-8859-1, and it's not possible to
U8 * free_little_p = NULL;
if (utf8_to_bytes_new_pv(&little_p, &llen, &free_little_p)) {
little_utf8 = false;

/* Here 'little_p' is in byte form, and 'free_little_p' is
* non-NULL if the original wasn't, and 'little_p' is pointing
* to new memory. We create a new SV for use by the rest of
* the routine that contains the new byte string, and donate it
* to temp to ensure it will get free()d */
if (free_little_p) {
little = temp = newSV_type(SVt_NULL);
sv_usepvn(temp, (char *) little_p, llen);
little_p = SvPVX_const(little);
}
}
else {
/* When the large string is ISO-8859-1, and it's not possible to
convert the small string to ISO-8859-1, then there is no
way that it could be found anywhere by index. */
retval = -1;
goto push_result;
}

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

Expand Down

0 comments on commit 9aaaeb6

Please sign in to comment.