This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_op_linklist(): use OPf_KIDS flags
authorDavid Mitchell <davem@iabyn.com>
Wed, 29 May 2019 14:03:42 +0000 (15:03 +0100)
committerDavid Mitchell <davem@iabyn.com>
Mon, 24 Jun 2019 10:40:07 +0000 (11:40 +0100)
This function just blindly assumes that cUNOPo->op_first is a valid
indication that the op has at least one child. This is successful *most*
of the time. Putting in an assertion caused t/op/lvref.t to fail.

Instead, check the OPf_KIDS flag.

op.c

diff --git a/op.c b/op.c
index 25f1faa..832e4ae 100644 (file)
--- a/op.c
+++ b/op.c
@@ -1603,17 +1603,15 @@ not be called directly.
 OP *
 Perl_op_linklist(pTHX_ OP *o)
 {
-    OP *first;
-
     PERL_ARGS_ASSERT_OP_LINKLIST;
 
     if (o->op_next)
        return o->op_next;
 
     /* establish postfix order */
-    first = cUNOPo->op_first;
-    if (first) {
+    if (o->op_flags & OPf_KIDS) {
         OP *kid;
+        OP *first = cUNOPo->op_first;
        o->op_next = LINKLIST(first);
        kid = first;
        for (;;) {