From: Father Chrysostomos Date: Tue, 13 Aug 2013 12:55:12 +0000 (-0700) Subject: Stop reset from clearing aliases to globs X-Git-Tag: upstream/5.20.0~2347 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=61e9f3fe948d8c2d882f7a4be9cb7d0ea1aefd65;p=platform%2Fupstream%2Fperl.git Stop reset from clearing aliases to globs If $z has been aliased to *foo, then reset("z") would turn off the SvOK flags on *foo, putting it in an inconsistent state. This could cause crashes. --- diff --git a/sv.c b/sv.c index de0831c..044dc9d 100644 --- a/sv.c +++ b/sv.c @@ -9181,7 +9181,7 @@ Perl_sv_resetpvn(pTHX_ const char *s, STRLEN len, HV * const stash) sv = GvSV(gv); if (sv && !SvREADONLY(sv)) { SV_CHECK_THINKFIRST_COW_DROP(sv); - SvOK_off(sv); + if (!isGV(sv)) SvOK_off(sv); } if (GvAV(gv)) { av_clear(GvAV(gv)); diff --git a/t/op/reset.t b/t/op/reset.t index f6c06d3..e592430 100644 --- a/t/op/reset.t +++ b/t/op/reset.t @@ -7,7 +7,7 @@ BEGIN { } use strict; -plan tests => 37; +plan tests => 39; package aiieee; @@ -127,6 +127,19 @@ is @scratch::an_array, 0, 'resetting array in the same gv as a ro scalar'; is @scratch::an_array, 0, 'resetting a hash in the same gv as a ro scalar'; is $scratch::an_array, 1, 'reset skips ro scalars in the same gv as av/hv'; +for our $z (*_) { + { + local *_; + reset "z"; + $z = 3; + () = *_{SCALAR}; + no warnings; + () = "$_"; # used to crash + } + is ref\$z, "GLOB", 'reset leaves real-globs-as-scalars as GLOBs'; + is $z, "*main::_", 'And the glob still has the right value'; +} + # This used to crash under threaded builds, because pmops were remembering # their stashes by name, rather than by pointer. fresh_perl_is( # it crashes more reliably with a smaller script