Infinite loop while generating gcc.1

Russ Allbery rra@stanford.edu
Sun Jan 14 20:18:00 GMT 2001


Joseph S Myers <jsm28@cam.ac.uk> writes:

> I can confirm that this version of perl does loop - apparently on the line

>     # Handle @r inside bold.
>     1 while s/B<((?:[^<>]*|I<[^<>*]*>)*)R<([^>]*)>/B<$1>${2}B</g;

The problem is that you have a * inside a *, which can cause exponential
backtracking.  In particular, the expression:

    (?:[^<>]*|I<[^<>*]*>)*

is problematic.  I think it's also slightly in error; [^<>*] looks odd
(why exclude * from the content of I<>?).

Try changing this line to:

    1 while s/B<((?:[^<>]|I<[^<>]*>)*)R<([^>]*)>/B<$1>${2}B</g;

and see if that works any better?  This just removes one * from inside the
parens in a way that should reduce the backtracking to linear rather than
exponential.

-- 
Russ Allbery (rra@stanford.edu)             < http://www.eyrie.org/~eagle/ >


More information about the Gcc-patches mailing list