On Wednesday, November 13, 2002, at 10:55  PM, Eike Grote wrote:

Hi,

Gakuji Ohtori <[EMAIL PROTECTED]> said:

The following code ends up with an error (segmentation fault):

$_ = 'x' x 1000;
/(a.|.){2,}/o;

The segmentation fault seems to happen only when the searched text ($_
in this example) is longer than 855 characters.

I know that m and n in the {m,n} qualifier are limited, but there isn't
a limitation for the length of the searched text, is there?
It looks like a problem caused by the regex engine. When running the
code with Perl 5.6.1 on Solaris 8 I don't get a segmentation fault,
but the following message when $_ has more than 32766 characters:

  Complex regular subexpression recursion limit (32766) exceeded
  at ./test.pl line 6.
Yeah, that's what "should" happen, I think. The regex engine has some limitation in terms of recursion, and the regex you're using recurses quite badly.

Here's what the docs `man perldiag` say about it:

Complex regular subexpression recursion limit (%d)
exceeded
(W regexp) The regular expression engine uses recur-
sion in complex situations where back-tracking is
required. Recursion depth is limited to 32766, or
perhaps less in architectures where the stack cannot
grow arbitrarily. ("Simple" and "medium" situations
are handled without recursion and are not subject to a
limit.) Try shortening the string under examination;
looping in Perl code (e.g. with "while") rather than
in the regular expression engine; or rewriting the
regular expression so that it is simpler or backtracks
less. (See the perlfaq2 manpage for information on
Mastering Regular Expressions.)


-Ken

Reply via email to