summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp_ctl.c5
-rw-r--r--t/op/for.t13
2 files changed, 16 insertions, 2 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index 7b3589da89..1ba7800682 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -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");
+ }
+}