]> code.delx.au - gnu-emacs/commitdiff
Fix rx matcher overflow without limiting
authorTassilo Horn <tsdh@gnu.org>
Mon, 14 Dec 2015 17:23:31 +0000 (18:23 +0100)
committerTassilo Horn <tsdh@gnu.org>
Mon, 14 Dec 2015 17:23:31 +0000 (18:23 +0100)
* lisp/textmodes/reftex-vars.el (reftex-label-regexps): Improve last
change to the regexp without imposing a limit on the length of the
options.

lisp/textmodes/reftex-vars.el

index fcab1367f7d7f49d8f1164e1d2ff9f6517832a71..9bc1d2d3af80d689afb85b39a36b04baa79af31a 100644 (file)
@@ -877,7 +877,17 @@ DOWNCASE    t:   Downcase words before using them."
       "\\\\label{\\(?1:[^}]*\\)}"
       ;; keyvals [..., label = {foo}, ...] forms used by ctable,
       ;; listings, minted, ...
-      "\\[[^][]\\{0,2000\\}\\<label[[:space:]]*=[[:space:]]*{?\\(?1:[^],}]+\\)}?")
+      ;;
+      ;; If you think the first shy group is a bit strange, it is like
+      ;; that in order not to overflow the regexp matcher stack in the
+      ;; presence of unbalanced brackets, i.e., a [ and then no
+      ;; closing bracket anymore.  In "[^[],]*,", the "*" repetition
+      ;; will be done without any need to record state for eventual
+      ;; backtracking because the "," is mutually exclusive with the
+      ;; "[^][,]", and the regexp matcher includes a special
+      ;; optimization for that case since it's common and very
+      ;; useful).  (Hint by Stefan Monnier)
+      "\\[\\(?:[^][,]*,\\)*[ \t]*\\<label[[:space:]]*=[[:space:]]*{?\\(?1:[^],}]+\\)}?")
     "List of regexps matching \\label definitions.
 The default value matches usual \\label{...} definitions and
 keyval style [..., label = {...}, ...] label definitions.  It is