summaryrefslogtreecommitdiff
path: root/pp_pack.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-04-30 20:41:29 +0000
committerNicholas Clark <nick@ccl4.org>2006-04-30 20:41:29 +0000
commitce399ba62db9cda174a31da7c5310c71b8a9adc4 (patch)
treee2ae23d56852f98a86a555d9e1c6b44ea4704d17 /pp_pack.c
parent12abf4f0efbd7338e12bce75e8fe77c524383458 (diff)
downloadperl-ce399ba62db9cda174a31da7c5310c71b8a9adc4.tar.gz
One part of pp_pack couldn't correctly handle surprises from UTF-8
overloading. p4raw-id: //depot/perl@28030
Diffstat (limited to 'pp_pack.c')
-rw-r--r--pp_pack.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/pp_pack.c b/pp_pack.c
index 97e22fde02..6e11eb2c3e 100644
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -2544,9 +2544,20 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
if (strchr("aAZ", lookahead.code)) {
if (lookahead.howlen == e_number) count = lookahead.length;
else {
- if (items > 0)
+ if (items > 0) {
+ if (SvGAMAGIC(*beglist)) {
+ /* Avoid reading the active data more than once
+ by copying it to a temporary. */
+ STRLEN len;
+ const char *const pv = SvPV_const(*beglist, len);
+ SV *const temp = sv_2mortal(newSVpvn(pv, len));
+ if (SvUTF8(*beglist))
+ SvUTF8_on(temp);
+ *beglist = temp;
+ }
count = DO_UTF8(*beglist) ?
sv_len_utf8(*beglist) : sv_len(*beglist);
+ }
else count = 0;
if (lookahead.code == 'Z') count++;
}