Patchwork genautomata fix

login
register
mail settings
Submitter Bernd Schmidt
Date Aug. 25, 2010, 10:51 a.m.
Message ID <4C74F5B8.40700@codesourcery.com>
Download mbox | patch
Permalink /patch/62669/
State New
Headers show

Comments

Bernd Schmidt - Aug. 25, 2010, 10:51 a.m.
This fixes a problem I found in genautomata while working on a new port.
 If you have extra parentheses in a regexp, e.g. "(s1)+s1w", we
construct a copy of the string "r1" in alloca'd memory on the stack.
Later, a pointer to that can escape because when there's only one
element in a string, we use the original string rather than the copy we
made on an obstack.

The extra parentheses are there because the scheduling description is
semi-generated and the input expression can expand to "(s1+x1)+s1w" in
other cases.

Fixed with this patch.  Bootstrapped and regression tested on
i686-linux.  Ok?


Bernd
* genautomata.c (gen_regexp_repeat, gen_regexp_allof,
	gen_regexp_oneof, gen_regexp_sequence): Use the string found
	in vector element 0 rather than the original string when there's
	only one element.
	(gen_regexp): Remove extra semicolon.
Richard Guenther - Aug. 25, 2010, 10:55 a.m.
On Wed, Aug 25, 2010 at 12:51 PM, Bernd Schmidt <bernds@codesourcery.com> wrote:
> This fixes a problem I found in genautomata while working on a new port.
>  If you have extra parentheses in a regexp, e.g. "(s1)+s1w", we
> construct a copy of the string "r1" in alloca'd memory on the stack.
> Later, a pointer to that can escape because when there's only one
> element in a string, we use the original string rather than the copy we
> made on an obstack.
>
> The extra parentheses are there because the scheduling description is
> semi-generated and the input expression can expand to "(s1+x1)+s1w" in
> other cases.
>
> Fixed with this patch.  Bootstrapped and regression tested on
> i686-linux.  Ok?

Ok.

Thanks,
Richard.

>
> Bernd
>

Patch

Index: genautomata.c
===================================================================
--- genautomata.c	(revision 296735)
+++ genautomata.c	(working copy)
@@ -1603,7 +1603,7 @@  gen_regexp_repeat (const char *str)
       return regexp;
     }
   else
-    return gen_regexp_el (str);
+    return gen_regexp_el (repeat_vect[0]);
 }
 
 /* Parse reservation STR which possibly contains separator '+'.  */
@@ -1629,7 +1629,7 @@  gen_regexp_allof (const char *str)
       return allof;
     }
   else
-    return gen_regexp_repeat (str);
+    return gen_regexp_repeat (allof_vect[0]);
 }
 
 /* Parse reservation STR which possibly contains separator '|'.  */
@@ -1655,7 +1655,7 @@  gen_regexp_oneof (const char *str)
       return oneof;
     }
   else
-    return gen_regexp_allof (str);
+    return gen_regexp_allof (oneof_vect[0]);
 }
 
 /* Parse reservation STR which possibly contains separator ','.  */
@@ -1680,7 +1680,7 @@  gen_regexp_sequence (const char *str)
       return sequence;
     }
   else
-    return gen_regexp_oneof (str);
+    return gen_regexp_oneof (sequence_vect[0]);
 }
 
 /* Parse construction reservation STR.  */
@@ -1688,7 +1688,7 @@  static regexp_t
 gen_regexp (const char *str)
 {
   reserv_str = str;
-  return gen_regexp_sequence (str);;
+  return gen_regexp_sequence (str);
 }
 
 /* Process a DEFINE_RESERVATION.