This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
sv_inc/dec_nomg(): croak on GVs etc
authorDavid Mitchell <davem@iabyn.com>
Wed, 18 Nov 2015 15:30:37 +0000 (15:30 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 18 Nov 2015 15:30:37 +0000 (15:30 +0000)
commitcb4547118517bc34243bbb938eeccfbd8016c64a
tree2bdb2f2aa58a67c94d06bc725dbe8922b7ce26b6
parent9a4196f3c96c8610228c991d38da5e0e1a517797
sv_inc/dec_nomg(): croak on GVs etc

RT #126637

Prior to v5.23.4-100-g20e9643, pp_postinc() etc checked whether the SV was
an AV, non-fake GV, or any other such non-modifiable thinngy; and if so,
called Perl_croak_no_modify(). That commit of mine removed the check, and
instead relied on the underlying sv_inc_nomg() function (called by
pp_postinc()) to do the checking instead. It turns out that while
sv_inc_nomg() etc does some checks, it wasn't as thorough as pp_postinc().
So something like

    my $y = $_++ for *FOO;

now crashes with an assertion failure in sv_inc_nomg() rather than
croaking.

This commit adds such checks to sv_inc_nomg() and sv_dec_nomg() - which
need them anyway, since they may be called from places other than
pp_postinc() etc.
sv.c
t/op/inc.t