]> code.delx.au - gnu-emacs/blobdiff - lisp/subr.el
Fix infloop in 'number-sequence'
[gnu-emacs] / lisp / subr.el
index 3ac61f9a45f6f96d02015c90fc1ab578fa1ec24c..43660d74377c8f80d1b71dbfc56445c6ce9c7497 100644 (file)
@@ -484,13 +484,16 @@ of course, also replace TO with a slightly larger value
       (list from)
     (or inc (setq inc 1))
     (when (zerop inc) (error "The increment can not be zero"))
-    (let (seq (n 0) (next from))
+    (let (seq (n 0) (next from) (last from))
       (if (> inc 0)
-          (while (<= next to)
+          ;; The (>= next last) condition protects against integer
+          ;; overflow in computing NEXT.
+          (while (and (>= next last) (<= next to))
             (setq seq (cons next seq)
                   n (1+ n)
+                  last next
                   next (+ from (* n inc))))
-        (while (>= next to)
+        (while (and (<= next last) (>= next to))
           (setq seq (cons next seq)
                 n (1+ n)
                 next (+ from (* n inc)))))