diff options
| author | Eli Zaretskii | 2016-05-27 12:17:15 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2016-05-27 12:17:15 +0300 |
| commit | f7ffc4b7d36041eba2abe9bc34927413f48056d4 (patch) | |
| tree | 21016675c4b801c9a7d40e8b69e369a9ca92429b /lisp | |
| parent | 4ab2673d87794dbbe4db33856c0dc69e4b06db71 (diff) | |
| download | emacs-f7ffc4b7d36041eba2abe9bc34927413f48056d4.tar.gz emacs-f7ffc4b7d36041eba2abe9bc34927413f48056d4.zip | |
Fix infloop in 'number-sequence'
* lisp/subr.el (number-sequence): Avoid overflow leading to an
infloop. (Bug#23627)
* test/automated/subr-tests.el (number-sequence-test): New test.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/subr.el | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 3ac61f9a45f..43660d74377 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -484,13 +484,16 @@ of course, also replace TO with a slightly larger value | |||
| 484 | (list from) | 484 | (list from) |
| 485 | (or inc (setq inc 1)) | 485 | (or inc (setq inc 1)) |
| 486 | (when (zerop inc) (error "The increment can not be zero")) | 486 | (when (zerop inc) (error "The increment can not be zero")) |
| 487 | (let (seq (n 0) (next from)) | 487 | (let (seq (n 0) (next from) (last from)) |
| 488 | (if (> inc 0) | 488 | (if (> inc 0) |
| 489 | (while (<= next to) | 489 | ;; The (>= next last) condition protects against integer |
| 490 | ;; overflow in computing NEXT. | ||
| 491 | (while (and (>= next last) (<= next to)) | ||
| 490 | (setq seq (cons next seq) | 492 | (setq seq (cons next seq) |
| 491 | n (1+ n) | 493 | n (1+ n) |
| 494 | last next | ||
| 492 | next (+ from (* n inc)))) | 495 | next (+ from (* n inc)))) |
| 493 | (while (>= next to) | 496 | (while (and (<= next last) (>= next to)) |
| 494 | (setq seq (cons next seq) | 497 | (setq seq (cons next seq) |
| 495 | n (1+ n) | 498 | n (1+ n) |
| 496 | next (+ from (* n inc))))) | 499 | next (+ from (* n inc))))) |