Prevent read-bytevector from corrupting data

Previously it was possible for an extra by to be introduced between multiple reads
This commit is contained in:
Justin Ethier 2020-03-06 12:33:05 -05:00
parent f2bf308746
commit b5a9bd24e1
2 changed files with 12 additions and 12 deletions

View file

@ -14,8 +14,7 @@ Features
Bug Fixes
- WIP - bug fixes to `read-bytevector` (return EOF, issue with sha2 sums)
- Fixed a bug in `read-bytevector` where an extra byte could be introduced when reading multiple chunks of data.
- Fixed a bug where variables defined within `define-syntax` and `let-syntax` are reported as unbound by the compiler.
## 0.15 - February 26, 2020

View file

@ -715,16 +715,17 @@
(car _port)))
(bv (make-bytevector k))
(loop (lambda (n)
(if (>= n k)
bv
(let ((b (read-u8 port)))
(cond
((eof-object? b)
(if (zero? n)
b ;; EOF
(bytevector-copy bv 0 n)))
((< n k)
(else
(bytevector-u8-set! bv n b)
(loop (+ n 1)))
(else bv))))))
(loop (+ n 1)))))))))
(loop 0)))
(define (read-bytevector! vec . o)
(let* ((in (if (pair? o) (car o) (current-input-port)))