get-bytevector-n! reads too many bytes
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Ikarus Scheme |
Fix Committed
|
Medium
|
Abdulaziz Ghuloum |
Bug Description
This test program demonstrates the bug:
(import (rnrs))
(define (print . x) (for-each display x) (newline))
(let ((test-file "reading-
(when (file-exists? test-file)
(delete-file test-file))
(let ((p (open-file-
(put-bytevector p '#vu8(1 2 3 4 5 6 7 8 9))
(close-port p))
(let ((p (open-file-
(buf (make-bytevector 10 #xff)))
(print "going to read 5 bytes: " (get-bytevector-n! p buf 0 5))
(print "result: " buf)
(print "going to read 1 byte: " (get-bytevector-n! p buf 5 1))
(print "result: " buf)
(unless (bytevector=? buf '#vu8(1 2 3 4 5 6 #xff #xff #xff #xff))
(print "the data is not correct"))
(close-port p)))
The problem is that the second get-bytevector-n! call reads too many bytes. Here is the output from the 64-bit build, rev 1816, on Debian Lenny amd64:
going to read 5 bytes: 5
result: #vu8(1 2 3 4 5 255 255 255 255 255)
going to read 1 byte: 4
result: #vu8(1 2 3 4 5 6 7 8 9 255)
the data is not correct
Fixed in 1818. Thanks.