Check bounds of ELT on &more in safe code.
authorStas Boukarev <stassats@gmail.com>
Mon, 1 Apr 2013 13:59:28 +0000 (17:59 +0400)
committerStas Boukarev <stassats@gmail.com>
Mon, 1 Apr 2013 13:59:28 +0000 (17:59 +0400)
Disable &more optimizations for ELT if safety = 3.

src/compiler/srctran.lisp
tests/seq.pure.lisp

index 2fc68a9..5858da9 100644 (file)
         `(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)
index 2941097..78d9b27 100644 (file)
                                     (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)))