Skip to content

Commit abe10ea

Browse files
committed
fix utf8 length magic handling for scalar reverse
fixes #17737
1 parent ece4280 commit abe10ea

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5898,6 +5898,7 @@ PP(pp_reverse)
58985898
sv_setsv(TARG, DEFSV);
58995899
XPUSHs(TARG);
59005900
}
5901+
SvSETMAGIC(TARG); /* remove any utf8 length magic */
59015902

59025903
up = SvPV_force(TARG, len);
59035904
if (len > 1) {

t/op/reverse.t

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BEGIN {
66
set_up_inc('../lib');
77
}
88

9-
plan tests => 24;
9+
plan tests => 25;
1010

1111
is(reverse("abc"), "cba", 'simple reverse');
1212

@@ -92,6 +92,15 @@ use Tie::Array;
9292
is($a, $c, 'Unicode string double reversal matches original');
9393
}
9494

95+
{
96+
# https://github.com/Perl/perl5/issues/17737
97+
# utf8 length magic handling
98+
# threw an assertion failure with -DDEBUGGING
99+
my @x;
100+
push @x, length reverse for split "-", "\x{100}--0";
101+
is($x[1], 0, "check set magic being called to clear length magic");
102+
}
103+
95104
# [perl #132544] stack pointer used to go wild when nullary reverse
96105
# required extending the stack
97106
for(0..1000){()=(0..$_,scalar reverse )}

0 commit comments

Comments
 (0)