]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid infloop in rect.el
authorEli Zaretskii <eliz@gnu.org>
Sat, 18 Feb 2017 09:32:45 +0000 (11:32 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 18 Feb 2017 09:32:45 +0000 (11:32 +0200)
* lisp/rect.el (rectangle--*-char): Avoid inflooping when called
with argument N whose absolute value is greater than 1.  (Bug#25773)

lisp/rect.el

index a4fa282791fe66526fe7f23921e9c4797fc246cb..a85101fddfa2b31e21d9f09aaa091b7dda7dfc67 100644 (file)
@@ -639,7 +639,8 @@ Activates the region if needed.  Only lasts until the region is deactivated."
   ;; rectangles" and not "visual rectangles", so in the presence of
   ;; bidirectional text things won't work well anyway.
   (if (< n 0) (rectangle--*-char other-cmd (- n))
-    (let ((col (rectangle--point-col (point))))
+    (let ((col (rectangle--point-col (point)))
+          (step 1))
       (while (> n 0)
         (let* ((bol (line-beginning-position))
                (eol (line-end-position))
@@ -647,7 +648,7 @@ Activates the region if needed.  Only lasts until the region is deactivated."
                (nextcol
                 (condition-case nil
                     (save-excursion
-                      (funcall cmd 1)
+                      (funcall cmd step)
                       (cond
                        ((> bol (point)) (- curcol 1))
                        ((< eol (point)) (+ col (1+ n)))
@@ -666,7 +667,8 @@ Activates the region if needed.  Only lasts until the region is deactivated."
            (t ;; (> nextcol curcol)
             (if (<= diff n)
                 (progn (cl-decf n diff) (setq col nextcol))
-              (setq col (if (< col nextcol) (+ col n) (- col n)) n 0))))))
+              (setq col (if (< col nextcol) (+ col n) (- col n)) n 0))))
+          (setq step (1+ step))))
       ;; FIXME: This rectangle--col-pos's move-to-column is wasted!
       (rectangle--col-pos col 'point))))