emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 4bf4002: Fix an infinite loop in c-end-of-macro. Sh


From: Alan Mackenzie
Subject: [Emacs-diffs] master 4bf4002: Fix an infinite loop in c-end-of-macro. Should fix bug #36484
Date: Thu, 4 Jul 2019 09:21:04 -0400 (EDT)

branch: master
commit 4bf4002906fe60fda35c5ea725ffc0463ca4c26b
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    Fix an infinite loop in c-end-of-macro.  Should fix bug #36484
    
    Also fix two faulty regexps, save-match-data, and check c-major-mode-is
    'c++-mode where needed.
    
    * lis/progmodes/cc-langs.el (c-last-c-comment-end-on-line-re)
    (c-last-open-c-comment-start-on-line-re): Handle repeated *s in regexp
    correctly.
    
    * lisp/progmodes/cc-engine.el (c-beginning-of-macro, c-end-of-macro): 
Protect
    the match-data with save-match-data around regexp operations.
    (c-end-of-macro): In the loop handling multiline block comments, check a
    comment actually is multiline.
    
    * lisp/progmodes/cc-mode.el (c-depropertize-CPP): Only call
    c-depropertize-raw-strings-in-region in C++ Mode.
---
 lisp/progmodes/cc-engine.el | 64 ++++++++++++++++++++++++---------------------
 lisp/progmodes/cc-langs.el  |  4 +--
 lisp/progmodes/cc-mode.el   |  9 ++++---
 3 files changed, 42 insertions(+), 35 deletions(-)

diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 4333823..2d4046d 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -310,20 +310,21 @@ comment at the start of cc-engine.el for more info."
          (beginning-of-line)
          (when (or (null lim)
                    (>= here lim))
-           (while
-               (progn
-                 (while (eq (char-before (1- (point))) ?\\)
-                   (forward-line -1))
-                 (when (and c-last-c-comment-end-on-line-re
-                            (re-search-forward
-                             c-last-c-comment-end-on-line-re pause t))
-                   (goto-char (match-end 1))
-                   (if (c-backward-single-comment)
-                       (progn
-                         (beginning-of-line)
-                         (setq pause (point)))
-                     (goto-char pause)
-                     nil)))))
+           (save-match-data
+             (while
+                 (progn
+                   (while (eq (char-before (1- (point))) ?\\)
+                     (forward-line -1))
+                   (when (and c-last-c-comment-end-on-line-re
+                              (re-search-forward
+                               c-last-c-comment-end-on-line-re pause t))
+                     (goto-char (match-end 1))
+                     (if (c-backward-single-comment)
+                         (progn
+                           (beginning-of-line)
+                           (setq pause (point)))
+                       (goto-char pause)
+                       nil))))))
 
          (back-to-indentation)
          (if (and (<= (point) here)
@@ -361,22 +362,25 @@ comment at the start of cc-engine.el for more info."
              c-macro-cache-start-pos nil
              c-macro-cache-syntactic nil
              c-macro-cache-no-comment nil))
-      (while
-         (progn
-           (while (progn
-                    (end-of-line)
-                    (when (and (eq (char-before) ?\\)
-                               (not (eobp)))
-                      (forward-char)
-                      t)))
-           (if (and c-last-open-c-comment-start-on-line-re
-                    (re-search-backward
-                     c-last-open-c-comment-start-on-line-re
-                     (c-point 'bol) t))
-               (progn
-                 (goto-char (match-beginning 1))
-                 (c-forward-single-comment))
-             nil)))
+      (save-match-data
+       (while
+           (progn
+             (while (progn
+                      (end-of-line)
+                      (when (and (eq (char-before) ?\\)
+                                 (not (eobp)))
+                        (forward-char)
+                        t)))
+             (let ((cand-EOM (point)))
+               (if (and c-last-open-c-comment-start-on-line-re
+                        (re-search-backward
+                         c-last-open-c-comment-start-on-line-re
+                         (c-point 'bol) t))
+                   (progn
+                     (goto-char (match-beginning 1))
+                     (and (c-forward-single-comment)
+                          (> (point) cand-EOM)))
+                 nil)))))
 
       (when (and (car c-macro-cache)
                 (> (point) (car c-macro-cache)) ; in case we have a
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 153d3fc..a0d4559 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1608,7 +1608,7 @@ backslash."
 current line, if any, or nil in those languages without block
 comments.  When a match is found, submatch 1 contains the comment
 ender."
-  t "\\(\\*/\\)\\([^*]\\|\\*[^/]\\)*$"
+  t "\\(\\*/\\)\\([^*]\\|\\*+[^/]\\)*$"
   awk nil)
 (c-lang-defvar c-last-c-comment-end-on-line-re
               (c-lang-const c-last-c-comment-end-on-line-re))
@@ -1618,7 +1618,7 @@ ender."
 current ine, if any, or nil in those languages without block
 comments.  When a match is found, submatch 1 contains the comment
 starter."
-  t "\\(/\\*\\)\\([^*]\\|\\*[^/]\\)*$"
+  t "\\(/\\*\\)\\([^*]\\|\\*+[^/]\\)*$"
   awk nil)
 (c-lang-defvar c-last-open-c-comment-start-on-line-re
               (c-lang-const c-last-open-c-comment-start-on-line-re))
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 8f4bb34..568fcee 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -934,7 +934,8 @@ Note that the style variables are always made local to the 
buffer."
       (goto-char (match-beginning 1))
       (setq m-beg (point))
       (c-end-of-macro)
-      (save-excursion (c-depropertize-raw-strings-in-region m-beg (point)))
+      (when (c-major-mode-is 'c++-mode)
+       (save-excursion (c-depropertize-raw-strings-in-region m-beg (point))))
       (c-clear-char-property-with-value m-beg (point) 'syntax-table '(1)))
 
     (while (and (< (point) end)
@@ -944,7 +945,8 @@ Note that the style variables are always made local to the 
buffer."
       (setq m-beg (point))
       (c-end-of-macro))
     (when (and ss-found (> (point) end))
-      (save-excursion (c-depropertize-raw-strings-in-region m-beg (point)))
+      (when (c-major-mode-is 'c++-mode)
+       (save-excursion (c-depropertize-raw-strings-in-region m-beg (point))))
       (c-clear-char-property-with-value m-beg (point) 'syntax-table '(1)))
 
     (while (and (< (point) c-new-END)
@@ -952,7 +954,8 @@ Note that the style variables are always made local to the 
buffer."
       (goto-char (match-beginning 1))
       (setq m-beg (point))
       (c-end-of-macro)
-      (save-excursion (c-depropertize-raw-strings-in-region m-beg (point)))
+      (when (c-major-mode-is 'c++-mode)
+       (save-excursion (c-depropertize-raw-strings-in-region m-beg (point))))
       (c-clear-char-property-with-value
        m-beg (point) 'syntax-table '(1)))))
 



reply via email to

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