[perl #40557] regexec.c saves context stack position improperly
Dave Bailey [Tue, 17 Oct 2006 09:37:28 +0000 (02:37 -0700)]
From: Dave Bailey (via RT) <perlbug-followup@perl.org>
Message-ID: <rt-3.5.HEAD-4979-1161103047-337.40557-75-0@perl.org>

p4raw-id: //depot/perl@29033

regexec.c
scope.c
scope.h

index 30dd354..c4d88cc 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -2094,7 +2094,7 @@ S_regtry(pTHX_ const regmatch_info *reginfo, char *startpos)
            PerlIO_printf(Perl_debug_log, "  setting stack tmpbase at %"IVdf"\n",
                          (IV)(PL_stack_sp - PL_stack_base));
            ));
-       SAVEI32(cxstack[cxstack_ix].blk_oldsp);
+       SAVESTACK_CXPOS();
        cxstack[cxstack_ix].blk_oldsp = PL_stack_sp - PL_stack_base;
        /* Otherwise OP_NEXTSTATE will free whatever on stack now.  */
        SAVETMPS;
diff --git a/scope.c b/scope.c
index 8923104..6a996ce 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -831,6 +831,10 @@ Perl_leave_scope(pTHX_ I32 base)
            i = SSPOPINT;
            PL_stack_sp = PL_stack_base + i;
            break;
+       case SAVEt_STACK_CXPOS:         /* blk_oldsp on context stack */
+           i = SSPOPINT;
+           cxstack[i].blk_oldsp = SSPOPINT;
+           break;
        case SAVEt_AELEM:               /* array element */
            value = (SV*)SSPOPPTR;
            i = SSPOPINT;
diff --git a/scope.h b/scope.h
index 9943a05..377a8b4 100644 (file)
--- a/scope.h
+++ b/scope.h
@@ -52,6 +52,7 @@
 #define SAVEt_COP_ARYBASE      41
 #define SAVEt_RE_STATE         42
 #define SAVEt_COMPILE_WARNINGS 43
+#define SAVEt_STACK_CXPOS      44
 
 #ifndef SCOPE_SAVES_SIGNAL_MASK
 #define SCOPE_SAVES_SIGNAL_MASK 0
@@ -205,6 +206,14 @@ Closing bracket on a callback.  See C<ENTER> and L<perlcall>.
        SSPUSHINT(SAVEt_COMPILE_WARNINGS);              \
     } STMT_END
 
+#define SAVESTACK_CXPOS() \
+    STMT_START {                                  \
+        SSCHECK(3);                               \
+        SSPUSHINT(cxstack[cxstack_ix].blk_oldsp); \
+        SSPUSHINT(cxstack_ix);                    \
+        SSPUSHINT(SAVEt_STACK_CXPOS);             \
+    } STMT_END
+
 #ifdef USE_ITHREADS
 #  define SAVECOPSTASH(c)      SAVEPPTR(CopSTASHPV(c))
 #  define SAVECOPSTASH_FREE(c) SAVESHAREDPV(CopSTASHPV(c))