diff options
| author | Alan Mackenzie | 2019-07-04 13:18:51 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2019-07-04 13:18:51 +0000 |
| commit | 4bf4002906fe60fda35c5ea725ffc0463ca4c26b (patch) | |
| tree | 7d5bd931e58bce4c94c6a8e33e61ece0b9f0ab82 | |
| parent | 5b48dab412c61980bca63a67a5d548d07e56b404 (diff) | |
| download | emacs-4bf4002906fe60fda35c5ea725ffc0463ca4c26b.tar.gz emacs-4bf4002906fe60fda35c5ea725ffc0463ca4c26b.zip | |
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.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 64 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 4 | ||||
| -rw-r--r-- | 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 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." | |||
| 310 | (beginning-of-line) | 310 | (beginning-of-line) |
| 311 | (when (or (null lim) | 311 | (when (or (null lim) |
| 312 | (>= here lim)) | 312 | (>= here lim)) |
| 313 | (while | 313 | (save-match-data |
| 314 | (progn | 314 | (while |
| 315 | (while (eq (char-before (1- (point))) ?\\) | 315 | (progn |
| 316 | (forward-line -1)) | 316 | (while (eq (char-before (1- (point))) ?\\) |
| 317 | (when (and c-last-c-comment-end-on-line-re | 317 | (forward-line -1)) |
| 318 | (re-search-forward | 318 | (when (and c-last-c-comment-end-on-line-re |
| 319 | c-last-c-comment-end-on-line-re pause t)) | 319 | (re-search-forward |
| 320 | (goto-char (match-end 1)) | 320 | c-last-c-comment-end-on-line-re pause t)) |
| 321 | (if (c-backward-single-comment) | 321 | (goto-char (match-end 1)) |
| 322 | (progn | 322 | (if (c-backward-single-comment) |
| 323 | (beginning-of-line) | 323 | (progn |
| 324 | (setq pause (point))) | 324 | (beginning-of-line) |
| 325 | (goto-char pause) | 325 | (setq pause (point))) |
| 326 | nil))))) | 326 | (goto-char pause) |
| 327 | nil)))))) | ||
| 327 | 328 | ||
| 328 | (back-to-indentation) | 329 | (back-to-indentation) |
| 329 | (if (and (<= (point) here) | 330 | (if (and (<= (point) here) |
| @@ -361,22 +362,25 @@ comment at the start of cc-engine.el for more info." | |||
| 361 | c-macro-cache-start-pos nil | 362 | c-macro-cache-start-pos nil |
| 362 | c-macro-cache-syntactic nil | 363 | c-macro-cache-syntactic nil |
| 363 | c-macro-cache-no-comment nil)) | 364 | c-macro-cache-no-comment nil)) |
| 364 | (while | 365 | (save-match-data |
| 365 | (progn | 366 | (while |
| 366 | (while (progn | 367 | (progn |
| 367 | (end-of-line) | 368 | (while (progn |
| 368 | (when (and (eq (char-before) ?\\) | 369 | (end-of-line) |
| 369 | (not (eobp))) | 370 | (when (and (eq (char-before) ?\\) |
| 370 | (forward-char) | 371 | (not (eobp))) |
| 371 | t))) | 372 | (forward-char) |
| 372 | (if (and c-last-open-c-comment-start-on-line-re | 373 | t))) |
| 373 | (re-search-backward | 374 | (let ((cand-EOM (point))) |
| 374 | c-last-open-c-comment-start-on-line-re | 375 | (if (and c-last-open-c-comment-start-on-line-re |
| 375 | (c-point 'bol) t)) | 376 | (re-search-backward |
| 376 | (progn | 377 | c-last-open-c-comment-start-on-line-re |
| 377 | (goto-char (match-beginning 1)) | 378 | (c-point 'bol) t)) |
| 378 | (c-forward-single-comment)) | 379 | (progn |
| 379 | nil))) | 380 | (goto-char (match-beginning 1)) |
| 381 | (and (c-forward-single-comment) | ||
| 382 | (> (point) cand-EOM))) | ||
| 383 | nil))))) | ||
| 380 | 384 | ||
| 381 | (when (and (car c-macro-cache) | 385 | (when (and (car c-macro-cache) |
| 382 | (> (point) (car c-macro-cache)) ; in case we have a | 386 | (> (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." | |||
| 1608 | current line, if any, or nil in those languages without block | 1608 | current line, if any, or nil in those languages without block |
| 1609 | comments. When a match is found, submatch 1 contains the comment | 1609 | comments. When a match is found, submatch 1 contains the comment |
| 1610 | ender." | 1610 | ender." |
| 1611 | t "\\(\\*/\\)\\([^*]\\|\\*[^/]\\)*$" | 1611 | t "\\(\\*/\\)\\([^*]\\|\\*+[^/]\\)*$" |
| 1612 | awk nil) | 1612 | awk nil) |
| 1613 | (c-lang-defvar c-last-c-comment-end-on-line-re | 1613 | (c-lang-defvar c-last-c-comment-end-on-line-re |
| 1614 | (c-lang-const c-last-c-comment-end-on-line-re)) | 1614 | (c-lang-const c-last-c-comment-end-on-line-re)) |
| @@ -1618,7 +1618,7 @@ ender." | |||
| 1618 | current ine, if any, or nil in those languages without block | 1618 | current ine, if any, or nil in those languages without block |
| 1619 | comments. When a match is found, submatch 1 contains the comment | 1619 | comments. When a match is found, submatch 1 contains the comment |
| 1620 | starter." | 1620 | starter." |
| 1621 | t "\\(/\\*\\)\\([^*]\\|\\*[^/]\\)*$" | 1621 | t "\\(/\\*\\)\\([^*]\\|\\*+[^/]\\)*$" |
| 1622 | awk nil) | 1622 | awk nil) |
| 1623 | (c-lang-defvar c-last-open-c-comment-start-on-line-re | 1623 | (c-lang-defvar c-last-open-c-comment-start-on-line-re |
| 1624 | (c-lang-const c-last-open-c-comment-start-on-line-re)) | 1624 | (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." | |||
| 934 | (goto-char (match-beginning 1)) | 934 | (goto-char (match-beginning 1)) |
| 935 | (setq m-beg (point)) | 935 | (setq m-beg (point)) |
| 936 | (c-end-of-macro) | 936 | (c-end-of-macro) |
| 937 | (save-excursion (c-depropertize-raw-strings-in-region m-beg (point))) | 937 | (when (c-major-mode-is 'c++-mode) |
| 938 | (save-excursion (c-depropertize-raw-strings-in-region m-beg (point)))) | ||
| 938 | (c-clear-char-property-with-value m-beg (point) 'syntax-table '(1))) | 939 | (c-clear-char-property-with-value m-beg (point) 'syntax-table '(1))) |
| 939 | 940 | ||
| 940 | (while (and (< (point) end) | 941 | (while (and (< (point) end) |
| @@ -944,7 +945,8 @@ Note that the style variables are always made local to the buffer." | |||
| 944 | (setq m-beg (point)) | 945 | (setq m-beg (point)) |
| 945 | (c-end-of-macro)) | 946 | (c-end-of-macro)) |
| 946 | (when (and ss-found (> (point) end)) | 947 | (when (and ss-found (> (point) end)) |
| 947 | (save-excursion (c-depropertize-raw-strings-in-region m-beg (point))) | 948 | (when (c-major-mode-is 'c++-mode) |
| 949 | (save-excursion (c-depropertize-raw-strings-in-region m-beg (point)))) | ||
| 948 | (c-clear-char-property-with-value m-beg (point) 'syntax-table '(1))) | 950 | (c-clear-char-property-with-value m-beg (point) 'syntax-table '(1))) |
| 949 | 951 | ||
| 950 | (while (and (< (point) c-new-END) | 952 | (while (and (< (point) c-new-END) |
| @@ -952,7 +954,8 @@ Note that the style variables are always made local to the buffer." | |||
| 952 | (goto-char (match-beginning 1)) | 954 | (goto-char (match-beginning 1)) |
| 953 | (setq m-beg (point)) | 955 | (setq m-beg (point)) |
| 954 | (c-end-of-macro) | 956 | (c-end-of-macro) |
| 955 | (save-excursion (c-depropertize-raw-strings-in-region m-beg (point))) | 957 | (when (c-major-mode-is 'c++-mode) |
| 958 | (save-excursion (c-depropertize-raw-strings-in-region m-beg (point)))) | ||
| 956 | (c-clear-char-property-with-value | 959 | (c-clear-char-property-with-value |
| 957 | m-beg (point) 'syntax-table '(1))))) | 960 | m-beg (point) 'syntax-table '(1))))) |
| 958 | 961 | ||