]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix an infinite loop in c-end-of-macro. Should fix bug #36484
authorAlan Mackenzie <acm@muc.de>
Thu, 4 Jul 2019 13:18:51 +0000 (13:18 +0000)
committerAlan Mackenzie <acm@muc.de>
Thu, 4 Jul 2019 13:18:51 +0000 (13:18 +0000)
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
lisp/progmodes/cc-langs.el
lisp/progmodes/cc-mode.el

index 4333823b2d2663da5fdcecf9d76ddacfa64cc3b4..2d4046d53267a1701a21ce83ead6c67fcb0c662c 100644 (file)
@@ -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
index 153d3fc260806593078165c724cc81879c5c1c78..a0d4559c2072b03b8ac37f5e3c75c47d5776cde8 100644 (file)
@@ -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))
index 8f4bb341acb977bd31137e09b50645b301d39b1c..568fceece24e7cf6960bb0a11a6143819f213068 100644 (file)
@@ -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)))))