Opened 4 years ago

Closed 3 years ago

#4427 closed bug (fixed)

hGetBuf sometimes reads fewer bytes than required

Reported by: rl Owned by: simonmar
Priority: highest Milestone: 7.0.1
Component: libraries/base Version: 7.1
Keywords: Cc:
Operating System: Windows Architecture: x86
Type of failure: Incorrect result at runtime Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The attached program repeatedly calls hGetBuf and prints how much it wanted to read and how many bytes hGetBuf returned. It should be run on a sufficiently large file. On Cygwin, the last 4 lines of the output are:

4 4
608 523
4 4
300 300

Note that we requested 608 bytes but hGetBuf only returned 523 even though we weren't at the end of file (since subsequent reads succeeded).

I suspect the bug is in GHC.IO.Handle.Text.bufReadEmpty, namely here:

  loop :: FD -> Int -> Int -> IO Int
  loop fd off bytes | bytes <= 0 = return off

It should probably return so_far + off.

Attachments (1)

Main.hs (1.2 KB) - added by rl 4 years ago.
Run with runghc Main.hs <file>

Download all attachments as: .zip

Change History (5)

Changed 4 years ago by rl

Run with runghc Main.hs <file>

comment:1 Changed 4 years ago by igloo

  • Milestone set to 7.0.1
  • Priority changed from normal to highest

comment:2 Changed 3 years ago by simonmar

  • Owner set to simonmar

comment:3 Changed 3 years ago by simonmar

  • Status changed from new to merge

I wasn't able to reproduce the bug (even with Cygwin), but your fix looks correct so I've applied it. Thanks!

Wed Oct 27 15:43:24 BST 2010  Simon Marlow <marlowsd@gmail.com>
  * hGetBuf: fix a case of a short read being returned (#4427)

comment:4 Changed 3 years ago by igloo

  • Resolution set to fixed
  • Status changed from merge to closed

Merged.

Note: See TracTickets for help on using tickets.