cisco/ChezScheme

bytevector-reference-ref & set! fail to correctly check size of bytevectors smaller than ptr-bytes - 1

Closed this issue · 1 comments

> (define rbv (make-reference-bytevector 1))
> (bytevector-reference-set! rbv 100 '(oh oh))
> (bytevector-reference-ref rbv 100)
(oh oh)
> rbv
#vu8(0)

The unsigned check ($fxu< (fx- (bytevector-length bv) (fx- (constant ptr-bytes) 1)) i) doesn't work as designed when the first argument goes negative.

Thanks for tracking that down! In the borken checks, I was trying to use the $fxu< trick used in other functions to guard against both a too-large value and a negative value in one step — but that doesn't work for a larger range (word-sized, in this case) that needs to be in bounds on both ends.