This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Revert "Fix off-by-one: avoid allocating an extra context"
authorChip Salzenberg <chip@pobox.com>
Wed, 28 Jul 2010 06:40:56 +0000 (23:40 -0700)
committerChip Salzenberg <chip@pobox.com>
Wed, 28 Jul 2010 06:40:56 +0000 (23:40 -0700)
This reverts commit 395b8e2d02eadc9b0639534410c39c530bc8a33d.
The fencepost error is coming from inside the programmer!

cop.h
scope.c

diff --git a/cop.h b/cop.h
index 7d90891..e5370c4 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -732,7 +732,7 @@ struct context {
 #define CxFOREACHDEF(c)        ((CxTYPE_is_LOOP(c) && CxTYPE(c) != CXt_LOOP_PLAIN) \
                         && ((c)->cx_type & CXp_FOR_DEF))
 
 #define CxFOREACHDEF(c)        ((CxTYPE_is_LOOP(c) && CxTYPE(c) != CXt_LOOP_PLAIN) \
                         && ((c)->cx_type & CXp_FOR_DEF))
 
-#define CXINC ((cxstack_ix + 1) < cxstack_max ? ++cxstack_ix : (cxstack_ix = cxinc()))
+#define CXINC (cxstack_ix < cxstack_max ? ++cxstack_ix : (cxstack_ix = cxinc()))
 
 /* 
 =head1 "Gimme" Values
 
 /* 
 =head1 "Gimme" Values
diff --git a/scope.c b/scope.c
index 2d9e383..92e9523 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -77,10 +77,10 @@ Perl_cxinc(pTHX)
     dVAR;
     const IV old_max = cxstack_max;
     cxstack_max = GROW(cxstack_max);
     dVAR;
     const IV old_max = cxstack_max;
     cxstack_max = GROW(cxstack_max);
-    Renew(cxstack, cxstack_max, PERL_CONTEXT);
+    Renew(cxstack, cxstack_max + 1, PERL_CONTEXT);     /* XXX should fix CXINC macro */
     /* Without any kind of initialising deep enough recursion
      * will end up reading uninitialised PERL_CONTEXTs. */
     /* Without any kind of initialising deep enough recursion
      * will end up reading uninitialised PERL_CONTEXTs. */
-    PoisonNew(cxstack + old_max, cxstack_max - old_max, PERL_CONTEXT);
+    PoisonNew(cxstack + old_max + 1, cxstack_max - old_max, PERL_CONTEXT);
     return cxstack_ix + 1;
 }
 
     return cxstack_ix + 1;
 }