@@ -3824,21 +3824,29 @@ PP(pp_index)
3824
3824
if (little_utf8 ) {
3825
3825
/* Well, maybe instead we might be able to downgrade the small
3826
3826
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
3831
3844
convert the small string to ISO-8859-1, then there is no
3832
3845
way that it could be found anywhere by index. */
3833
3846
retval = -1 ;
3834
3847
goto push_result ;
3835
3848
}
3836
3849
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 );
3842
3850
} else {
3843
3851
temp = newSVpvn (little_p , llen );
3844
3852
0 commit comments