This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Infinite loop while generating gcc.1


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/>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]