This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
op_free() remove redundant !kid test
authorDavid Mitchell <davem@iabyn.com>
Tue, 19 Mar 2019 11:15:21 +0000 (11:15 +0000)
committerDavid Mitchell <davem@iabyn.com>
Tue, 19 Mar 2019 11:26:35 +0000 (11:26 +0000)
and replace with an assert.

If an op has the OPf_KIDS flag, then cUNOPo->op_first must be non-null.
So testing for !kid doesn't do much, especially as on the previous line
we dereference it anyway.

op.c

diff --git a/op.c b/op.c
index afee9fc..95a3061 100644 (file)
--- a/op.c
+++ b/op.c
@@ -884,9 +884,10 @@ Perl_op_free(pTHX_ OP *o)
 
         if (o->op_flags & OPf_KIDS) {
             OP *kid, *nextkid;
+            assert(cUNOPo->op_first); /* OPf_KIDS implies op_first non-null */
             for (kid = cUNOPo->op_first; kid; kid = nextkid) {
                 nextkid = OpSIBLING(kid); /* Get before next freeing kid */
-                if (!kid || kid->op_type == OP_FREED)
+                if (kid->op_type == OP_FREED)
                     /* During the forced freeing of ops after
                        compilation failure, kidops may be freed before
                        their parents. */