develooper Front page | perl.perl5.porters | Postings from October 2003

[PATCH 5.8.1 CORE] Internal fixes to source-code coordinate calculations in regcomp.c

Thread Next
From:
Eric Promislow
Date:
October 9, 2003 01:52
Subject:
[PATCH 5.8.1 CORE] Internal fixes to source-code coordinate calculations in regcomp.c
Message ID:
20031008174242.A17544@ActiveState.com

The problem:
  This module calculates source-code coordinates for the atoms in a
  regular expression.  This patch fixes four sets of errors:

    1. The coordinates of SUSPEND nodes were off by one.

    2. The length of constant strings was returning garbage values
       due to an uninitialized variable.

    3. The length of an unrecognized escape sequence (like "\F")
       is 2, as this is the number of characters in the original
       source.

    4. The length of relocated nodes was not being set, returning
       whatever value was previously assigned to the node.  For example,
       the length of the "+" atom in "\d+" was left as 2.

Application:
  This is a standard patch on src/Core/regcomp.c

Tests:
  No tests are submitted, as the data generated by these changes in
  regcomp.c is not exposed at the Perl language level.

The Patch:
--- regcomp.c-old	Wed Oct  8 15:45:00 2003
+++ regcomp.c	Wed Oct  8 16:00:04 2003
@@ -2506,8 +2506,8 @@
 	    if (paren == '>')
 		node = SUSPEND, flag = 0;
 	    reginsert(pRExC_state, node,ret);
-	    Set_Node_Offset(ret, oregcomp_parse);
-	    Set_Node_Length(ret,  RExC_parse - oregcomp_parse + 2);
+	    Set_Node_Cur_Length(ret);
+	    Set_Node_Offset(ret, parse_start + 1);
 	    ret->flags = flag;
 	    regtail(pRExC_state, ret, reg_node(pRExC_state, TAIL));
 	}
@@ -2788,7 +2788,7 @@
 {
     register regnode *ret = 0;
     I32 flags;
-    char *parse_start = 0;
+    char *parse_start = RExC_parse;
 
     *flagp = WORST;		/* Tentatively. */
 
@@ -3051,6 +3051,7 @@
 	default:
 	    /* Do not generate `unrecognized' warnings here, we fall
 	       back into the quick-grab loop below */
+	    parse_start--;
 	    goto defchar;
 	}
 	break;
@@ -4420,6 +4421,7 @@
               RExC_parse - RExC_start,
               RExC_offsets[0])); 
 	Set_Node_Offset(place, RExC_parse);
+	Set_Node_Length(place, 1);
     }
     src = NEXTOPER(place);
     FILL_ADVANCE_NODE(place, op);

------------------------------------------------
Eric Promislow
Visual Studio .NET Plugins Development Lead
EricP@ActiveState.com
--

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About