Subject: bug#22146: Stack overflow in reftex-parse-all

From: Mosè Giordano <[email-masked]>
Date: Sun, 13 Dec 2015 12:53:30 +0100

Hi David,

2015-12-12 11:05 GMT+01:00 David Kastrup <[email-masked]>:
> Mosè Giordano <[email-masked]> writes:
>
>> I'm not completely sure how to fix a "Stack overflow in regexp
>> matcher" error: the problem is that it matches nothing or too much?
>
> It has incomplete matches in too many different ways.  Something like
>
> .*.*
>
> is a trivial example of stuff that can usually match in too many
> different ways.  A nice regexp is one where each character of an
> incomplete match is only a candidate for a single component of the
> regexp.
>
> An ugly regexp is one where adding one character to the match grows the
> possibly match/pattern correspondences by more than one repeatedly.

Thanks for the explanation, but in this concrete case I can reproduce
the bug in Emacs 24.5 evaluating

    (re-search-forward "\\[[^]]*\\<label")

at the beginning of the buffer suggested by Nils.  So, it doesn't seem
there is an incomplete match, but simply "\\[[^]]*" is too greedy.
This also explains why closing the bracket works around the bug.

Tassilo, does `reftex-parse-all' fail with larger buffers in Emacs 25?
 If so, we can make the regexp less greedy by specifying the maximum
number of non-closing brackets characters, something like

    "\\[[^]]\{0,1000\}\\<label"

I don't know if this can somehow affect performances.

Bye,
Mosè