diff options
| author | Alan Mackenzie | 2017-10-30 17:33:03 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2017-10-30 17:33:03 +0000 |
| commit | 18331d00da7394f169b842f9e701568fede9b402 (patch) | |
| tree | 7fc1d499b9713aa087134914f7ba46dbe700bb8b | |
| parent | edde35e6f8c21979035824ae1845c33e0a5e0da0 (diff) | |
| download | emacs-18331d00da7394f169b842f9e701568fede9b402.tar.gz emacs-18331d00da7394f169b842f9e701568fede9b402.zip | |
Fix "Args out of range" error in c-determine-limit. Fixes bug #28598.
* lisp/progmodes/cc-engine.el (c-determine-limit-get-base): If the candidate
position for BASE is below point-min, scan forward to the end of the current
literal.
(c-determine-limit): Add an extra arm to the final cond form, testing for BASE
being at point-min.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index db201a6322f..6f39cc64338 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -5189,16 +5189,25 @@ comment at the start of cc-engine.el for more info." | |||
| 5189 | ;; Get a "safe place" approximately TRY-SIZE characters before START. | 5189 | ;; Get a "safe place" approximately TRY-SIZE characters before START. |
| 5190 | ;; This defsubst doesn't preserve point. | 5190 | ;; This defsubst doesn't preserve point. |
| 5191 | (let* ((pos (max (- start try-size) (point-min))) | 5191 | (let* ((pos (max (- start try-size) (point-min))) |
| 5192 | (s (c-state-semi-pp-to-literal pos))) | 5192 | (s (c-state-semi-pp-to-literal pos)) |
| 5193 | (or (car (cddr s)) pos))) | 5193 | (cand (or (car (cddr s)) pos))) |
| 5194 | (if (>= cand (point-min)) | ||
| 5195 | cand | ||
| 5196 | (parse-partial-sexp pos start nil nil (car s) 'syntax-table) | ||
| 5197 | (point)))) | ||
| 5194 | 5198 | ||
| 5195 | (defun c-determine-limit (how-far-back &optional start try-size) | 5199 | (defun c-determine-limit (how-far-back &optional start try-size) |
| 5196 | ;; Return a buffer position HOW-FAR-BACK non-literal characters from START | 5200 | ;; Return a buffer position HOW-FAR-BACK non-literal characters from |
| 5197 | ;; (default point). This is done by going back further in the buffer then | 5201 | ;; START (default point). The starting position, either point or |
| 5198 | ;; searching forward for literals. The position found won't be in a | 5202 | ;; START may not be in a comment or string. |
| 5199 | ;; literal. We start searching for the sought position TRY-SIZE (default | 5203 | ;; |
| 5200 | ;; twice HOW-FAR-BACK) bytes back from START. This function must be fast. | 5204 | ;; The position found will not be before POINT-MIN and won't be in a |
| 5201 | ;; :-) | 5205 | ;; literal. |
| 5206 | ;; | ||
| 5207 | ;; We start searching for the sought position TRY-SIZE (default | ||
| 5208 | ;; twice HOW-FAR-BACK) bytes back from START. | ||
| 5209 | ;; | ||
| 5210 | ;; This function must be fast. :-) | ||
| 5202 | (save-excursion | 5211 | (save-excursion |
| 5203 | (let* ((start (or start (point))) | 5212 | (let* ((start (or start (point))) |
| 5204 | (try-size (or try-size (* 2 how-far-back))) | 5213 | (try-size (or try-size (* 2 how-far-back))) |
| @@ -5254,6 +5263,8 @@ comment at the start of cc-engine.el for more info." | |||
| 5254 | (+ (car elt) (- count how-far-back))) | 5263 | (+ (car elt) (- count how-far-back))) |
| 5255 | ((eq base (point-min)) | 5264 | ((eq base (point-min)) |
| 5256 | (point-min)) | 5265 | (point-min)) |
| 5266 | ((> base (- start try-size)) ; Can only happen if we hit point-min. | ||
| 5267 | (car elt)) | ||
| 5257 | (t | 5268 | (t |
| 5258 | (c-determine-limit (- how-far-back count) base try-size)))))) | 5269 | (c-determine-limit (- how-far-back count) base try-size)))))) |
| 5259 | 5270 | ||