This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix size-miscalculation upgrading LISTOP TO LOOPOP
authorDavid Mitchell <davem@iabyn.com>
Fri, 9 Aug 2019 10:11:19 +0000 (11:11 +0100)
committerDavid Mitchell <davem@iabyn.com>
Fri, 9 Aug 2019 10:11:19 +0000 (11:11 +0100)
RT #134344

My recent commit v5.31.2-54-g8c47b5bce7 broke some CAN modules because
the code in Perl_newFOROP() wasn't accounting for the overhead in the
opslot struct when deciding whether an allocated LISTOP was large enough
to be upgraded in-place to a LOOPOP.

op.c

diff --git a/op.c b/op.c
index 5d0b1da..8625104 100644 (file)
--- a/op.c
+++ b/op.c
@@ -9287,7 +9287,8 @@ Perl_newFOROP(pTHX_ I32 flags, OP *sv, OP *expr, OP *block, OP *cont)
     /* upgrade loop from a LISTOP to a LOOPOP;
      * keep it in-place if there's space */
     if (loop->op_slabbed
-        && OpSLOT(loop)->opslot_size < SIZE_TO_PSIZE(sizeof(LOOP)))
+        &&    OpSLOT(loop)->opslot_size
+            < SIZE_TO_PSIZE(sizeof(LOOP)) + OPSLOT_HEADER_P)
     {
         /* no space; allocate new op */
        LOOP *tmp;