fixed a bug in get-bytevector-n! when n == 1.
This commit is contained in:
parent
b8cfdbbf66
commit
6e7f0ccf84
|
@ -1863,15 +1863,15 @@
|
|||
[else
|
||||
($bytevector-set! s i x)
|
||||
(let f ([p p] [s s] [start i] [i 1] [c c])
|
||||
(let ([x (get-u8 p)])
|
||||
(cond
|
||||
[(eof-object? x) i]
|
||||
[else
|
||||
($bytevector-set! s ($fx+ start i) x)
|
||||
(let ([i ($fxadd1 i)])
|
||||
(if ($fx= i c)
|
||||
i
|
||||
(f p s start i c)))])))])))]
|
||||
(cond
|
||||
[($fx= i c) i]
|
||||
[else
|
||||
(let ([x (get-u8 p)])
|
||||
(cond
|
||||
[(eof-object? x) i]
|
||||
[else
|
||||
($bytevector-set! s ($fx+ start i) x)
|
||||
(f p s start ($fx+ i 1) c)]))]))])))]
|
||||
[($fx= c 0) 0]
|
||||
[else (die 'get-bytevector-n! "count is negative" c)])))
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
1815
|
||||
1817
|
||||
|
|
|
@ -706,8 +706,21 @@
|
|||
(put-bytevector p '#vu8(0)))
|
||||
(assert (equal? (e) (make-bytevector (* 86 2) 0))))))
|
||||
|
||||
(define (test-get-bytevector-n)
|
||||
(let ((p (open-bytevector-input-port '#vu8(1 2 3 4 5 6 7 8 9)))
|
||||
(buf (make-bytevector 10 #xff)))
|
||||
(let ([buf1
|
||||
(begin
|
||||
(printf "going to read 5 bytes: ~s\n" (get-bytevector-n! p buf 0 5))
|
||||
(printf "result: ~s\n" buf)
|
||||
(bytevector-copy buf))])
|
||||
(printf "going to read 1 byte: ~s\n" (get-bytevector-n! p buf 5 1))
|
||||
(printf "result: ~s\n" buf)
|
||||
(unless (bytevector=? buf '#vu8(1 2 3 4 5 6 #xff #xff #xff #xff))
|
||||
(error 'test "the data is not correct" buf1 buf)))))
|
||||
|
||||
(define (run-tests)
|
||||
(test-get-bytevector-n)
|
||||
(test-custom-binary-input-ports)
|
||||
(test-custom-binary-output-ports)
|
||||
(run-exhaustive-tests)
|
||||
|
|
Loading…
Reference in New Issue