]> code.delx.au - gnu-emacs/commitdiff
Fix infinite loop in delete-consecutive-dups
authorShigeru Fukaya <shigeru.fukaya@gmail.com>
Sun, 26 Jul 2015 17:43:10 +0000 (10:43 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 26 Jul 2015 17:43:28 +0000 (10:43 -0700)
* lisp/subr.el (delete-consecutive-dups): Work even if the last
element is nil (Bug#20588).  Avoid rescan of a circular list in
deletion of last element.

lisp/subr.el

index e2c1baea442bd06e2ab5cc79cb514ccdd57062f1..bfdc0ff4a130cfd6c18b91bdd2dcbb6c740fc075 100644 (file)
@@ -440,16 +440,16 @@ one is kept."
 First and last elements are considered consecutive if CIRCULAR is
 non-nil."
   (let ((tail list) last)
-    (while (consp tail)
+    (while (cdr tail)
       (if (equal (car tail) (cadr tail))
          (setcdr tail (cddr tail))
-       (setq last (car tail)
+       (setq last tail
              tail (cdr tail))))
     (if (and circular
-            (cdr list)
-            (equal last (car list)))
-       (nbutlast list)
-      list)))
+            last
+            (equal (car tail) (car list)))
+       (setcdr last nil)))
+  list)
 
 (defun number-sequence (from &optional to inc)
   "Return a sequence of numbers from FROM to TO (both inclusive) as a list.