This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid reusing foreach itervar if magic got tacked onto it
[perl5.git] / pp_hot.c
index d0fdbfc..29f6542 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1460,7 +1460,9 @@ PP(pp_iter)
            char *max = SvPV((SV*)av, maxlen);
            if (!SvNIOK(cur) && SvCUR(cur) <= maxlen) {
 #ifndef USE_THREADS                      /* don't risk potential race */
            char *max = SvPV((SV*)av, maxlen);
            if (!SvNIOK(cur) && SvCUR(cur) <= maxlen) {
 #ifndef USE_THREADS                      /* don't risk potential race */
-               if (SvREFCNT(*cx->blk_loop.itervar) == 1) {
+               if (SvREFCNT(*cx->blk_loop.itervar) == 1
+                   && !SvMAGICAL(*cx->blk_loop.itervar))
+               {
                    /* safe to reuse old SV */
                    sv_setsv(*cx->blk_loop.itervar, cur);
                }
                    /* safe to reuse old SV */
                    sv_setsv(*cx->blk_loop.itervar, cur);
                }
@@ -1486,7 +1488,9 @@ PP(pp_iter)
            RETPUSHNO;
 
 #ifndef USE_THREADS                      /* don't risk potential race */
            RETPUSHNO;
 
 #ifndef USE_THREADS                      /* don't risk potential race */
-       if (SvREFCNT(*cx->blk_loop.itervar) == 1) {
+       if (SvREFCNT(*cx->blk_loop.itervar) == 1
+           && !SvMAGICAL(*cx->blk_loop.itervar))
+       {
            /* safe to reuse old SV */
            sv_setiv(*cx->blk_loop.itervar, cx->blk_loop.iterix++);
        }
            /* safe to reuse old SV */
            sv_setiv(*cx->blk_loop.itervar, cx->blk_loop.iterix++);
        }