diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b11633c..169036d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/scheme/base.sld b/scheme/base.sld index a34d69ba..6e297ef9 100644 --- a/scheme/base.sld +++ b/scheme/base.sld @@ -715,16 +715,17 @@ (car _port))) (bv (make-bytevector k)) (loop (lambda (n) - (let ((b (read-u8 port))) - (cond - ((eof-object? b) - (if (zero? n) - b ;; EOF - (bytevector-copy bv 0 n))) - ((< n k) - (bytevector-u8-set! bv n b) - (loop (+ n 1))) - (else bv)))))) + (if (>= n k) + bv + (let ((b (read-u8 port))) + (cond + ((eof-object? b) + (if (zero? n) + b ;; EOF + (bytevector-copy bv 0 n))) + (else + (bytevector-u8-set! bv n b) + (loop (+ n 1))))))))) (loop 0))) (define (read-bytevector! vec . o) (let* ((in (if (pair? o) (car o) (current-input-port)))