diff options
-rw-r--r-- | pp_ctl.c | 5 | ||||
-rw-r--r-- | t/op/for.t | 13 |
2 files changed, 16 insertions, 2 deletions
@@ -2142,7 +2142,10 @@ PP(pp_enteriter) SV** svp = &GvSV(gv); itervarp = (void *)gv; itersave = *svp; - *svp = newSV(0); + if (LIKELY(itersave)) + SvREFCNT_inc_simple_void_NN(itersave); + else + *svp = newSV(0); cxtype |= CXp_FOR_GV; } else { diff --git a/t/op/for.t b/t/op/for.t index 65a746497a..ef60f4d622 100644 --- a/t/op/for.t +++ b/t/op/for.t @@ -5,7 +5,7 @@ BEGIN { require "./test.pl"; } -plan(111); +plan(112); # A lot of tests to check that reversed for works. @@ -620,3 +620,14 @@ is(fscope(), 1, 'return via loop in sub'); ok(!defined $foo, "NULL GvSV"); } } + +# make sure storing an int in a NULL GvSV is ok + +{ + local $foo = "boo"; + { + local *foo; + for $foo (1..2) {} + ok(!defined $foo, "NULL GvSV int iterator"); + } +} |