[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 45987b3: Merge remote-tracking branch 'origin/fix/s
From: |
Nicolas Petton |
Subject: |
[Emacs-diffs] master 45987b3: Merge remote-tracking branch 'origin/fix/subsequence-error-with-negative-sequences' |
Date: |
Sat, 08 Aug 2015 19:55:12 +0000 |
branch: master
commit 45987b34535e5ae97fa14535630e283f34af94dd
Merge: c208eef feadec3
Author: Nicolas Petton <address@hidden>
Commit: Nicolas Petton <address@hidden>
Merge remote-tracking branch
'origin/fix/subsequence-error-with-negative-sequences'
---
lisp/emacs-lisp/cl-extra.el | 4 +++-
lisp/emacs-lisp/seq.el | 7 ++++++-
test/automated/seq-tests.el | 7 ++++++-
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el
index 101864d..9742014 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 9eed36e..038b20e 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))
diff --git a/test/automated/seq-tests.el b/test/automated/seq-tests.el
index 3643ce5..74c0700 100644
--- a/test/automated/seq-tests.el
+++ b/test/automated/seq-tests.el
@@ -187,7 +187,12 @@ Evaluate BODY for each created sequence.
(should-not (seq-subseq '(1 2 3) 3))
(should (seq-subseq '(1 2 3) -3))
(should-error (seq-subseq '(1 2 3) 1 4))
- (should (seq-subseq '(1 2 3) 1 3)))
+ (should (seq-subseq '(1 2 3) 1 3))
+ (should-error (seq-subseq '() -1))
+ (should-error (seq-subseq [] -1))
+ (should-error (seq-subseq "" -1))
+ (should-not (seq-subseq '() 0))
+ (should-error(seq-subseq '() 0 -1)))
(ert-deftest test-seq-concatenate ()
(with-test-sequences (seq '(2 4 6))