This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp.c: Can grow scalar by less
authorKarl Williamson <public@khwilliamson.com>
Sun, 29 Jan 2012 17:41:14 +0000 (10:41 -0700)
committerKarl Williamson <public@khwilliamson.com>
Sun, 29 Jan 2012 20:58:12 +0000 (13:58 -0700)
The max expansion when a Latin1 character is folded and converted to
UTF-8 is '2' bytes per input byte, not the more general case.

pp.c

diff --git a/pp.c b/pp.c
index 1dc0460..29ed4c6 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -4218,7 +4218,9 @@ PP(pp_fc)
                     SvCUR_set(dest, len);
                     len = sv_utf8_upgrade_flags_grow(dest,
                                                 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
-                                                (send -s) * UTF8_MAX_FOLD_CHAR_EXPAND + 1);
+                                               /* The max expansion for latin1
+                                                * chars is 1 byte becomes 2 */
+                                                (send -s) * 2 + 1);
                     d = (U8*)SvPVX(dest) + len;
 
                     CAT_UNI_TO_UTF8_TWO_BYTE(d, GREEK_SMALL_LETTER_MU);