emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/auctex 11d8029 16/23: Signal an error if auto-parser re


From: Tassilo Horn
Subject: [elpa] externals/auctex 11d8029 16/23: Signal an error if auto-parser regexp has too many groups
Date: Sat, 23 Jan 2021 04:10:09 -0500 (EST)

branch: externals/auctex
commit 11d802916f54c3c52fae4d7f0ed02857661e7f9c
Author: Tassilo Horn <tsdh@gnu.org>
Commit: Tassilo Horn <tsdh@gnu.org>

    Signal an error if auto-parser regexp has too many groups
    
    In (pathological) documents which activate too many styles adding
    entries to TeX-auto-regexp-list, the full regular expression built for
    auto-parsing may contain more groups than emacs supports (which is 255
    at this point of time).  Therefore, signal a clear error in that case
    instead of failing unpredictably by resultant problems.
    
    Also, fix another spot where duplicate entries could have been added.
    
    * tex.el (TeX-auto-parse-region): Signal an error if the generated
    auto-parser regexp has more than 255 groups.
    * latex.el (LaTeX-common-initialization): Ensure we don't add
    duplicate entries to TeX-auto-full-regexp-list.
---
 latex.el | 5 +++--
 tex.el   | 9 +++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/latex.el b/latex.el
index c25cc24..6a8b2fd 100644
--- a/latex.el
+++ b/latex.el
@@ -6217,8 +6217,9 @@ function would return non-nil and `(match-string 1)' 
would return
                     (cons (concat "\\" (nth 0 x)) (nth 1 x)))
                   LaTeX-section-list)))
 
-  (set (make-local-variable 'TeX-auto-full-regexp-list)
-       (append LaTeX-auto-regexp-list plain-TeX-auto-regexp-list))
+  (setq-local TeX-auto-full-regexp-list
+              (delete-dups (append LaTeX-auto-regexp-list
+                                   plain-TeX-auto-regexp-list)))
 
   (LaTeX-set-paragraph-start)
   (setq paragraph-separate
diff --git a/tex.el b/tex.el
index 671d287..b59aee0 100644
--- a/tex.el
+++ b/tex.el
@@ -4244,6 +4244,15 @@ you should not use something like `[\\(]' for a 
character range."
                              "\\)"))
              syms
              lst)
+        ;; TODO: Emacs allows at most 255 groups in a regexp, see the
+        ;; "#define MAX_REGNUM 255" in regex-emacs.c.  If our regex
+        ;; has more groups, bad things may happen, e.g.,
+        ;; (match-beginning 271) returns nil although the regexp that
+        ;; matched contains group number 271.  Sadly, MAX_REGNUM is
+        ;; not exposed to Lisp, so we need to hard-code it here (and
+        ;; sometimes check if it increased in newer Emacs versions).
+        (when (> count 255)
+          (error "The TeX auto-parser's regexp has too many groups (%d)" 
count))
         (setq count 0)
         (goto-char (if end (min end (point-max)) (point-max)))
         (while (re-search-backward regexp beg t)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]