Skip to content

Commit

Permalink
Fix the SEARCH transform on bad indexes.
Browse files Browse the repository at this point in the history
Fixes lp#1769218
  • Loading branch information
stassats committed May 4, 2018
1 parent d8ccebf commit 166100a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-data-list.lisp-expr
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ possibly temporarily, because it might be used internally."
"LL-KWDS-RESTP" "LL-KWDS-KEYP" "LL-KWDS-ALLOWP"
"MAKE-MACRO-LAMBDA"
"PROPER-LIST-OF-LENGTH-P" "PROPER-LIST-P"
"LIST-OF-LENGTH-AT-LEAST-P"
"LIST-OF-LENGTH-AT-LEAST-P" "SEQUENCE-OF-LENGTH-AT-LEAST-P"
"LIST-WITH-LENGTH-P"
"SINGLETON-P" "ENSURE-LIST"
"MISSING-ARG"
Expand Down
9 changes: 9 additions & 0 deletions src/code/early-extensions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@
(or (zerop n) ; since anything can be considered an improper list of length 0
(and (consp rest) (rec (cdr rest) (1- n))))))

(defun sequence-of-length-at-least-p (sequence length)
(etypecase sequence
(list
(list-of-length-at-least-p sequence length))
(vector
(>= (length sequence) length))
(sequence
(>= (length sequence) length))))

;;; Is X is a positive prime integer?
(defun positive-primep (x)
;; This happens to be called only from one place in sbcl-0.7.0, and
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/seqtran.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,9 @@
(length pattern))
(t
(give-up-ir1-transform))))
(pattern (if (= (- pattern-end pattern-start) 1)
(pattern (if (and (= (- pattern-end pattern-start) 1)
(sequence-of-length-at-least-p pattern
(1+ pattern-start)))
(elt pattern pattern-start)
(give-up-ir1-transform))))
(macrolet ((maybe-arg (arg &optional (key (keywordicate arg)))
Expand Down
5 changes: 5 additions & 0 deletions tests/bad-code.pure.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,8 @@
(checked-compile
'(lambda () (encode-universal-time 0 0 0 1 1 1900 -1))
:allow-style-warnings t))))

(with-test (:name :search-transform-bad-index)
(checked-compile
'(lambda (a)
(search '(0 1 0 2) a :start1 4 :end1 5))))

0 comments on commit 166100a

Please sign in to comment.