regcomp.c: Make SSC node clone safe
authorKarl Williamson <public@khwilliamson.com>
Wed, 12 Mar 2014 19:15:44 +0000 (13:15 -0600)
committerKarl Williamson <public@khwilliamson.com>
Wed, 12 Mar 2014 19:27:55 +0000 (13:27 -0600)
This just sets the ptr field in the Synthetic Start Class that will be
passed to regexec.c NULL, and clarifies the comments in regcomp.h.  See
the thread starting at http://markmail.org/message/2txwaqnjco6zodeo

regcomp.c
regcomp.h

index c5dbe13..d72d344 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -1445,6 +1445,9 @@ S_ssc_finalize(pTHX_ RExC_state_t *pRExC_state, regnode_ssc *ssc)
     set_ANYOF_arg(pRExC_state, (regnode *) ssc, invlist,
                                 NULL, NULL, NULL, FALSE);
 
+    /* Make sure is clone-safe */
+    ssc->invlist = NULL;
+
     if (ANYOF_POSIXL_SSC_TEST_ANY_SET(ssc)) {
         ANYOF_FLAGS(ssc) |= ANYOF_POSIXL;
     }
index 700d6c1..3bb1a53 100644 (file)
--- a/regcomp.h
+++ b/regcomp.h
@@ -217,14 +217,15 @@ struct regnode_charclass_class {
     U32 classflags;                            /* and run-time */
 };
 
-/* A synthetic start class; is a regnode_charclass_posixl_fold, plus an extra
- * SV*, used only during its construction and which is not used by regexec.c.
- * Note that the 'next_off' field is unused, as the SSC stands alone, so there
- * is never a next node.  Also, there is no alignment issue, becase these are
- * declared or allocated as a complete unit so the compiler takes care of
- * alignment.  This is unlike ithe other regnodes which are allocated in terms
- * of multiples of a single-argument regnode.  Because there is no alignment
- * issue, these can have a pointer field */
+/* A synthetic start class (SSC); is a regnode_charclass_posixl_fold, plus an
+ * extra SV*, used only during its construction and which is not used by
+ * regexec.c.  Note that the 'next_off' field is unused, as the SSC stands
+ * alone, so there is never a next node.  Also, there is no alignment issue,
+ * becase these are declared or allocated as a complete unit so the compiler
+ * takes care of alignment.  This is unlike the other regnodes which are
+ * allocated in terms of multiples of a single-argument regnode.  SSC nodes can
+ * have a pointer field because there is no alignment issue, and because it is
+ * set to NULL after construction, before any cloning of the pattern */
 struct regnode_ssc {
     U8 flags;                          /* ANYOF_POSIXL bit must go here */
     U8  type;
@@ -232,7 +233,10 @@ struct regnode_ssc {
     U32 arg1;
     char bitmap[ANYOF_BITMAP_SIZE];    /* both compile-time */
     U32 classflags;                    /* and run-time */
-    SV* invlist;                        /* list of code points matched */
+
+    /* Auxiliary, only used during construction; NULL afterwards: list of code
+     * points matched */
+    SV* invlist;
 };
 
 /*  We take advantage of 'next_off' not otherwise being used in the SSC by