From 942b8f7916e62c00d059f7c3df2a4437c2fc18e1 Mon Sep 17 00:00:00 2001
From: dtc <dtc>
Date: Thu, 14 Sep 2000 14:34:37 +0000
Subject: [PATCH] Take a little more care with the :start and :end arguments to
 the subseq transform, limiting the :end to the string length and the :start
 to the :end.

---
 compiler/generic/vm-tran.lisp | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/compiler/generic/vm-tran.lisp b/compiler/generic/vm-tran.lisp
index c93773ec4..d40a25191 100644
--- a/compiler/generic/vm-tran.lisp
+++ b/compiler/generic/vm-tran.lisp
@@ -5,7 +5,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/generic/vm-tran.lisp,v 1.39 2000/01/14 19:48:43 dtc Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/generic/vm-tran.lisp,v 1.40 2000/09/14 14:34:37 dtc Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -140,9 +140,11 @@
 
 (deftransform subseq ((string start &optional (end nil))
 		      (simple-string t &optional t))
-  '(let* ((length (- (or end (length string))
-		     start))
-	  (result (make-string length)))
+  '(let* ((length (length string))
+	  (end (if end (min end length) length))
+	  (start (min start end))
+	  (size (- end start))
+	  (result (make-string size)))
      (declare (optimize (safety 0)))
      (bit-bash-copy string
 		    (the index
@@ -150,7 +152,7 @@
 			    vector-data-bit-offset))
 		    result
 		    vector-data-bit-offset
-		    (the index (* length vm:byte-bits)))
+		    (the index (* size vm:byte-bits)))
      result))
 
 
-- 
GitLab