Summary

utf8: Errors in xstring-copy! and utf8-case-map

Metadata

Description

utf8-srfi-13 has a problem where it's missing a set of parentheses; it's passing the procedure - as one of the arguments to +, causing an infinite loop in string-xcopy!:

 #;1> (use utf8-srfi-13)
 #;2> (define s1 "foo")
 #;3> (define s2 (make-string 3))
 #;4> (string-xcopy! s2 0 s1 1)
 ;; never stops, should put "oof" in s2

This is simple to fix:

 Index: utf8-srfi-13.scm
 ===================================================================
 --- utf8-srfi-13.scm	(revision 26685)
 +++ utf8-srfi-13.scm	(working copy)
 @@ -570,7 +570,7 @@
  
  (define (string-xcopy target tstart s from . opt)
    (let-optionals* opt ((to1 #f) (start 0) (end (utf8-string-length s)))
 -    (let ((to (or to1 (+ from - end start))))
 +    (let ((to (or to1 (+ from (- end start)))))
        (string-append (utf8-substring target 0 tstart)
                       (xsubstring s from to start end)
                       (utf8-substring target

There's another bug in utf8-case-map, which I don't know how to trigger (might be worthwhile trying to figure that out to add it as a regression test). There's two places where u32vector-ref is called with only one argument. This is also simple to fix, but as I wasn't able to trigger the bug I'm not sure this is correct:

 Index: utf8-case-map.scm
 ===================================================================
 --- utf8-case-map.scm	(revision 26685)
 +++ utf8-case-map.scm	(working copy)
 @@ -122,9 +122,9 @@
       (>= hi lo)
       (cond
         ((= i (u32vector-ref tab (* lo 4)))
 -        (u32vector-ref (+ (* lo 4) off)))
 +        (u32vector-ref tab (+ (* lo 4) off)))
         ((= i (u32vector-ref tab (* hi 4)))
 -        (u32vector-ref (+ (* hi 4) off)))
 +        (u32vector-ref tab (+ (* hi 4) off)))
         (else
          (let loop ((a lo) (b hi))
            (if (= a b)

These bugs were found by the scrutinizer, see http://parenteses.org/mario/misc/specialize-report/install/utf8.html

Changes and comments

[2012-07-20 16:40:00 UTC] ashinn changed status from new to closed

[2012-07-20 16:40:00 UTC] ashinn set resolution to fixed