Skip to content

Commit 55efd82

Browse files
authored
Merge pull request #98 from input-output-hk/jdral/bugfix-buffered-reads
Bugfix for `hGetBufExactly` and `hGetBufExactlyAt`
2 parents bac668b + b350d54 commit 55efd82

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

fs-api/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
This was already the semantics when using `hOpen` from the `ioHasFS` instance,
2020
but it was not reflected in the `allowExisting` function. `allowExisting
2121
Readmode` now returns `MustExist` instead of `AllowExisting`.
22+
* Bugfix: `hGetBufExactly` and `hGetBufExactlyAt` would previously try to read
23+
too many bytes in the presence of partial reads. These functions now properly
24+
count the number of remaining bytes that have to be read.
2225

2326
## 0.3.0.1 -- 2024-10-02
2427

fs-api/src/System/FS/API.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ hGetBufExactly hfs h buf bufOff c = go c bufOff
263263
go !remainingCount !currentBufOff
264264
| remainingCount == 0 = pure c
265265
| otherwise = do
266-
readBytes <- hGetBufSome hfs h buf currentBufOff c
266+
readBytes <- hGetBufSome hfs h buf currentBufOff remainingCount
267267
if readBytes == 0 then
268268
throwIO FsError {
269269
fsErrorType = FsReachedEOF
@@ -294,7 +294,7 @@ hGetBufExactlyAt hfs h buf bufOff c off = go c off bufOff
294294
go !remainingCount !currentOffset !currentBufOff
295295
| remainingCount == 0 = pure c
296296
| otherwise = do
297-
readBytes <- hGetBufSomeAt hfs h buf currentBufOff c currentOffset
297+
readBytes <- hGetBufSomeAt hfs h buf currentBufOff remainingCount currentOffset
298298
if readBytes == 0 then
299299
throwIO FsError {
300300
fsErrorType = FsReachedEOF

0 commit comments

Comments
 (0)