get-bytevector-n! reads too many bytes

Bug #393431 reported by Gwen Weinholt
6
This bug affects 1 person
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-bug-test.bin"))
  (when (file-exists? test-file)
    (delete-file test-file))
  (let ((p (open-file-output-port test-file)))
    (put-bytevector p '#vu8(1 2 3 4 5 6 7 8 9))
    (close-port p))
  (let ((p (open-file-input-port test-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

Related branches

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Fixed in 1818. Thanks.

Changed in ikarus:
assignee: nobody → Abdulaziz Ghuloum (aghuloum)
importance: Undecided → Medium
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.