Ticket #280 (new defect)

Opened 14 years ago

eof error

Reported by: rik.vanmechelen@… Owned by: soegaard
Priority: critical Milestone:
Component: soegaard/bit-io.plt Keywords: eof error
Cc: Version: (2 0)
Racket Version: 4.2.4


It says in the comments that when you reach an eof it should return #f when reading.
I got an error that the bitwise-and got eof as first argument
the fix for this is:
;;;new if statement to chech for eof first

(define (read-few-bits n)

(if (eof-object? buffer)

(let ((value (bitwise-and buffer ; all bits in buffer

(sub1 (<<1 mask)))))

(set! bits-in-buffer (- bits-in-buffer n))
(set! mask (>> mask n))
(>> value bits-in-buffer)))) ; remove extra bits

;;;added and with not eof?
((and (= n 1) ; read one bit

(not (eof-object? buffer)))

(let ((value (if (bit-set? buffer mask) 1 0)))

(set! mask (>>1 mask))
(set! bits-in-buffer (sub1 bits-in-buffer))

Rik Vanmechelen
Vrije Universiteit Brussel

Note: See TracTickets for help on using tickets.