diff options
author | Nicolas Petton <nicolas@petton.fr> | 2015-08-08 21:54:45 +0200 |
---|---|---|
committer | Nicolas Petton <nicolas@petton.fr> | 2015-08-08 21:54:45 +0200 |
commit | 45987b34535e5ae97fa14535630e283f34af94dd (patch) | |
tree | a1b428b39bbd513111e11f59558a815b2548d728 /lisp/emacs-lisp | |
parent | c208eefcef22183a03d0f03a95a830a14242970c (diff) | |
parent | feadec307da148af70cf87013c99771ca4db91e4 (diff) | |
download | emacs-45987b34535e5ae97fa14535630e283f34af94dd.tar.gz emacs-45987b34535e5ae97fa14535630e283f34af94dd.tar.bz2 emacs-45987b34535e5ae97fa14535630e283f34af94dd.zip |
Merge remote-tracking branch 'origin/fix/subsequence-error-with-negative-sequences'
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/cl-extra.el | 4 | ||||
-rw-r--r-- | lisp/emacs-lisp/seq.el | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el index 101864d3721..9742014db0c 100644 --- a/lisp/emacs-lisp/cl-extra.el +++ b/lisp/emacs-lisp/cl-extra.el @@ -518,7 +518,9 @@ This sets the values of: `cl-most-positive-float', `cl-most-negative-float', (defun cl-subseq (seq start &optional end) "Return the subsequence of SEQ from START to END. If END is omitted, it defaults to the length of the sequence. -If START or END is negative, it counts from the end." +If START or END is negative, it counts from the end. +Signal an error if START or END are outside of the sequence (i.e +too large if positive or too small if negative)" (declare (gv-setter (lambda (new) (macroexp-let2 nil new new diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 9eed36eb68c..038b20e3b5e 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -221,12 +221,17 @@ TESTFN is used to compare elements, or `equal' if TESTFN is nil." (defun seq-subseq (seq start &optional end) "Return the subsequence of SEQ from START to END. If END is omitted, it defaults to the length of the sequence. -If START or END is negative, it counts from the end." +If START or END is negative, it counts from the end. + +Signal an error if START or END are outside of the sequence (i.e +too large if positive or too small if negative)" (cond ((or (stringp seq) (vectorp seq)) (substring seq start end)) ((listp seq) (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)))))) + (unless (>= start 0) + (error "%s" errtext)) (when (> start 0) (setq seq (nthcdr (1- start) seq)) (or seq (error "%s" errtext)) |