master: Fix off-by-one errors in crlf swar routines

stassats via Sbcl-commits <[email protected]> Sun, 24 May 2026 03:00:42 +0000
Newsgroups gmane.lisp.steel-bank.cvs
Message-ID <[email protected]>
The branch "master" has been updated in SBCL:
       via  4ad7155f4fb38f5b54312169f7924fcf7b713a22 (commit)
      from  8817a07e6c37a73086b29d420fa72fb59aa356ba (commit)

- Log -----------------------------------------------------------------
commit 4ad7155f4fb38f5b54312169f7924fcf7b713a22
Author: Stas Boukarev <[email protected]>
Date:   Sun May 24 05:58:11 2026 +0300

    Fix off-by-one errors in crlf swar routines
---
 src/code/external-formats/enc-basic.lisp | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/code/external-formats/enc-basic.lisp b/src/code/external-formats/enc-basic.lisp
index 7238cd6a4..3d78353d9 100644
--- a/src/code/external-formats/enc-basic.lisp
+++ b/src/code/external-formats/enc-basic.lisp
@@ -671,8 +671,8 @@
     (let* ((head (buffer-head ibuf))
            (tail (buffer-tail ibuf))
            (sap (buffer-sap ibuf))
-           (n (logand (min (- end start)
-                           (- (- tail head) 1))
+           (n (logand (min (1- (- end start))
+                           (1- (- tail head)))
                       (- 2)))
            (repeat (ldb (byte 16 0) #x0101010101010101))
            (ascii-mask (* 128 repeat))
@@ -1313,8 +1313,8 @@
     (let* ((head (buffer-head ibuf))
            (tail (buffer-tail ibuf))
            (sap (buffer-sap ibuf))
-           (n (logand (min (- end start)
-                           (- (- tail head) 1))
+           (n (logand (min (1- (- end start))
+                           (1- (- tail head)))
                       (- 2)))
            (repeat (ldb (byte 16 0) #x0101010101010101))
            (ascii-mask (* 128 repeat))
@@ -1334,7 +1334,7 @@
                      (incf head 2)
                      (incf string-offset 1))
                     ((= (ash word -8) 13)
-                     (setf (sap-ref-8 string-sap string-offset) word)
+                     (setf (sap-ref-8 string-sap string-offset) (ldb (byte 8 0) word))
                      (incf head 1)
                      (incf string-offset 1))
                     (t
@@ -1353,8 +1353,8 @@
     (let* ((head (buffer-head ibuf))
            (tail (buffer-tail ibuf))
            (sap (buffer-sap ibuf))
-           (n (logand (min (- end start)
-                           (- (- tail head) 1))
+           (n (logand (min (1- (- end start))
+                           (1- (- tail head)))
                       (- 2)))
            (repeat (ldb (byte 16 0) #x0101010101010101))
            (ascii-mask (* 128 repeat))

-----------------------------------------------------------------------


hooks/post-receive
-- 
SBCL