From e626db9d157d8790efe3762a7f46cc347161f8e8 Mon Sep 17 00:00:00 2001 From: Stas Boukarev Date: Mon, 1 Apr 2013 17:59:28 +0400 Subject: [PATCH] Check bounds of ELT on &more in safe code. Disable &more optimizations for ELT if safety = 3. --- src/compiler/srctran.lisp | 10 ++++++---- tests/seq.pure.lisp | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/compiler/srctran.lisp b/src/compiler/srctran.lisp index 2fc68a9..5858da9 100644 --- a/src/compiler/srctran.lisp +++ b/src/compiler/srctran.lisp @@ -4152,10 +4152,12 @@ `(car (nthcdr ,n ,list))))) (define-source-transform elt (seq n) - (multiple-value-bind (context count) (possible-rest-arg-context seq) - (if context - `(%rest-ref ,n ,seq ,context ,count) - (values nil t)))) + (if (policy *lexenv* (= safety 3)) + (values nil t) + (multiple-value-bind (context count) (possible-rest-arg-context seq) + (if context + `(%rest-ref ,n ,seq ,context ,count) + (values nil t))))) ;;; CAxR -> %REST-REF (defun source-transform-car (list nth) diff --git a/tests/seq.pure.lisp b/tests/seq.pure.lisp index 2941097..78d9b27 100644 --- a/tests/seq.pure.lisp +++ b/tests/seq.pure.lisp @@ -370,3 +370,10 @@ (t #'shuffle)) size type) #'< :key #'car)))))))) + +(with-test (:name &more-elt-index-too-large) + (assert (raises-error? (funcall + (compile nil '(lambda (&rest args) + (declare (optimize safety)) + (elt args 0)))) + sb-kernel:index-too-large-error))) -- 1.7.10.4