summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/seq.el
diff options
context:
space:
mode:
authorLeo Liu <sdl.web@gmail.com>2015-01-18 14:03:59 +0800
committerLeo Liu <sdl.web@gmail.com>2015-01-18 14:04:31 +0800
commit253d44bd27b7d90b614b6b968a3b125eeb0a48f2 (patch)
tree1c78770cc1a038e6ac5ebaa569d6a2044c1cfe41 /lisp/emacs-lisp/seq.el
parent909126de0f6d2e53aec44c97abccee5b32b25f28 (diff)
downloademacs-253d44bd27b7d90b614b6b968a3b125eeb0a48f2.tar.gz
emacs-253d44bd27b7d90b614b6b968a3b125eeb0a48f2.tar.bz2
emacs-253d44bd27b7d90b614b6b968a3b125eeb0a48f2.zip
Fix seq-subseq and cl-subseq for bad bounding indices
Fixes: debbugs:19434 debbugs:19519 * lisp/emacs-lisp/cl-extra.el (cl-subseq): Use seq-subseq and fix multiple evaluation. * lisp/emacs-lisp/seq.el (seq-subseq): Throw bad bounding indices error. * test/automated/seq-tests.el (test-seq-subseq): Add more tests.
Diffstat (limited to 'lisp/emacs-lisp/seq.el')
-rw-r--r--lisp/emacs-lisp/seq.el10
1 files changed, 7 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index f6740c7d7f5..b28153b7f81 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -197,14 +197,18 @@ If END is omitted, it defaults to the length of the sequence.
If START or END is negative, it counts from the end."
(cond ((or (stringp seq) (vectorp seq)) (substring seq start end))
((listp seq)
- (let (len)
+ (let (len (errtext (format "Bad bounding indices: %s, %s" start end)))
(and end (< end 0) (setq end (+ end (setq len (seq-length seq)))))
(if (< start 0) (setq start (+ start (or len (setq len (seq-length seq))))))
- (if (> start 0) (setq seq (nthcdr start seq)))
+ (when (> start 0)
+ (setq seq (nthcdr (1- start) seq))
+ (or seq (error "%s" errtext))
+ (setq seq (cdr seq)))
(if end
(let ((res nil))
- (while (>= (setq end (1- end)) start)
+ (while (and (>= (setq end (1- end)) start) seq)
(push (pop seq) res))
+ (or (= (1+ end) start) (error "%s" errtext))
(nreverse res))
(seq-copy seq))))
(t (error "Unsupported sequence: %s" seq))))