From: Alan Mackenzie Date: Thu, 4 Jul 2019 13:18:51 +0000 (+0000) Subject: Fix an infinite loop in c-end-of-macro. Should fix bug #36484 X-Git-Tag: emacs-27.0.90~2107 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4bf4002906fe60fda35c5ea725ffc0463ca4c26b;p=emacs.git 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. --- diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 4333823b2d2..2d4046d5326 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 153d3fc2608..a0d4559c207 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 8f4bb341acb..568fceece24 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)))))