~ chicken-core (chicken-5) 189876e82624332ded0652d29ce4efaeb493ea68


commit 189876e82624332ded0652d29ce4efaeb493ea68
Author:     felix <felix@call-with-current-continuation.org>
AuthorDate: Mon Apr 15 12:48:23 2024 +0200
Commit:     Mario Domenech Goulart <mario@parenteses.org>
CommitDate: Mon Apr 15 19:33:56 2024 +0200

    Fixed off-by-one-errors in end-limit of substring[-ci]=?
    
    Fixes #1835
    
    Signed-off-by: Mario Domenech Goulart <mario@parenteses.org>

diff --git a/data-structures.scm b/data-structures.scm
index 642d2a59..ad09d26b 100644
--- a/data-structures.scm
+++ b/data-structures.scm
@@ -160,7 +160,7 @@
   (let* ((maxlen (fxmin (fx- (##sys#size s1) start1)
                         (fx- (##sys#size s2) start2)))
          (len (if n
-                  (begin (##sys#check-range n 0 maxlen 'substring=?) n)
+                  (begin (##sys#check-range n 0 (fx+ maxlen 1) 'substring=?) n)
                   maxlen)))
     (##core#inline "C_substring_compare" s1 s2 start1 start2 len) ) )
 
@@ -175,7 +175,7 @@
   (let* ((maxlen (fxmin (fx- (##sys#size s1) start1)
                         (fx- (##sys#size s2) start2)))
          (len (if n
-                  (begin (##sys#check-range n 0 maxlen 'substring-ci=?) n)
+                  (begin (##sys#check-range n 0 (fx+ maxlen 1) 'substring-ci=?) n)
                   maxlen)))
     (##core#inline "C_substring_compare_case_insensitive"
 		   s1 s2 start1 start2 len) ) )
diff --git a/tests/data-structures-tests.scm b/tests/data-structures-tests.scm
index 17a3dd58..eb779531 100644
--- a/tests/data-structures-tests.scm
+++ b/tests/data-structures-tests.scm
@@ -46,6 +46,8 @@
 (assert (= 2 (substring-index-ci "o\x00bar" "foo\x00BAR")))
 (assert (not (substring=? "foo\x00a" "foo\x00b" 1 1)))
 (assert (not (substring-ci=? "foo\x00a" "foo\x00b" 1 1)))
+(assert (substring=? "foo" "foo" 0 0 3))
+(assert (substring-ci=? "foo" "foo" 0 0 3))
 (assert (not (substring-index "o\x00bar" "foo\x00baz")))
 (assert (not (substring-index-ci "o\x00bar" "foo\x00baz")))
 (assert (= 0 (substring-index "" "")))
@@ -62,6 +64,7 @@
 (assert-error (substring-ci=? "a" "a" 0 -2))
 (assert-error (substring-ci=? "a" "a" 0 0 2))
 (assert-error (substring-ci=? "a" "a" 0 0 -2))
+(assert-error (substring-ci=? "a" "a" 0 0 2))
 (assert-error (substring-index "" "a" 2))
 (assert-error (substring-index "a" "b" 2))
 (assert (not (substring-index "a" "b" 1)))
Trap