#!r6rs
(import (vicare)
(vicare checks)
(vicare system $fx)
(vicare system $strings))
(define ($string-reverse! str start past)
(do ((i ($fxsub1 past) ($fxsub1 i))
(j start ($fxadd1 j)))
(($fx<= i j)
str)
(let ((ci ($string-ref str i)))
($string-set! str i ($string-ref str j))
($string-set! str j ci))))
(check
(let ((S (string-copy "ciao")))
($string-reverse! S 0 4)
S)
=> "oaic")
the crash does not occur if we change some unsafe core primitive application with the corresponding safe core primitive. For example, changing $fx<= to fx<=? avoids the error.
Notice that the following code with vectors works fine:
(internal-body
(define ($vector-reverse! str start past)
(do ((i ($fxsub1 past) ($fxsub1 i))
(j start ($fxadd1 j)))
(($fx<= i j)
str)
(let ((ci ($vector-ref str i)))
($vector-set! str i ($vector-ref str j))
($vector-set! str j ci))))
(check
(let ((S (vector-copy '#(c i a o))))
($vector-reverse! S 0 4)
S)
=> '#(o a i c)))
The following program crashes at run-time:
the crash does not occur if we change some unsafe core primitive application with the corresponding safe core primitive. For example, changing
$fx<=
tofx<=?
avoids the error.Notice that the following code with vectors works fine: