This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Create NOTHING node when would have been 0 length EXACT
authorKarl Williamson <public@khwilliamson.com>
Fri, 10 Aug 2012 15:11:11 +0000 (09:11 -0600)
committerKarl Williamson <public@khwilliamson.com>
Sun, 12 Aug 2012 01:32:31 +0000 (19:32 -0600)
It's peculiar circumstances indeed that would get to this point in the
code with an EXACT node to be created, but nothing to populate it with.
Perhaps it is impossible; I'm not sure.  But commit
5f820f894e71b6970a5aa0fd763a84b647fd628a changed the behavior, which I
discovered in later re-reading the code.  Probably the node would be
populated with a single NUL.  Just in case it is possible to get here
under these peculiar circumstances, this commit adds code to handle the
case, with a NOTHING node instead of a 0 length EXACT.

regcomp.c

index 1987df3..0dc7ab8 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -10946,7 +10946,15 @@ tryagain:
        loopdone:   /* Jumped to when encounters something that shouldn't be in
                       the node */
 
+            /* I (khw) don't know if you can get here with zero length, but the
+             * old code handled this situation by creating a zero-length EXACT
+             * node.  Might as well be NOTHING instead */
+            if (len == 0) {
+                OP(ret) = NOTHING;
+            }
+            else{
                 alloc_maybe_populate_EXACT(pRExC_state, ret, flagp, len, ender);
+            }
 
            RExC_parse = p - 1;
             Set_Node_Cur_Length(ret); /* MJD */