This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #123763] Clear target on my $_; split
authorFather Chrysostomos <sprout@cpan.org>
Sun, 1 Mar 2015 06:31:25 +0000 (22:31 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 1 Mar 2015 06:31:25 +0000 (22:31 -0800)
commit55b3980349c58171a77894903fd928262fb081f2
tree02acf5011b735a8065feca7ab7d8d11808687475
parent179b3fadcd608f8420b9976426de4456289a8bc5
[perl #123763] Clear target on my $_; split

If a lexical $_ is in scope, then the first argument to split, which
starts out as a match op, will get the pad offset of $_ as its target,
since that’s how implicit lexical $_=~ usually works.

ck_split changes that first argument to a pushre op.  The target
was not being cleared.  That did not cause any problems, until
v5.21.4-408-gfd017c0, which optimised lexical @array = split to write
to split @array directly, by storing making lexical array’s pad offset
the pushre’s target.

You can see the obvious conflict there.  We end up trying to split to
$_, which is not an array.  On a debugging build, you get an assertion
failure when trying to extend $_.  Make the split list long enough,
and you get a crash on non-debugging builds.

debugging$ ./miniperl -e 'my $_; split'
Use of my $_ is experimental at -e line 1.
Assertion failed: (SvTYPE(av) == SVt_PVAV), function Perl_av_extend, file av.c, line 70.

non-debugging$ ./miniperl -e 'my $_; split //, "a"x100000'
Use of my $_ is experimental at -e line 1.
Segmentation fault: 11
op.c
t/base/lex.t