[GHC] #4427: hGetBuf sometimes reads fewer bytes than required

GHC cvs-ghc at haskell.org
Fri Oct 22 05:24:27 EDT 2010


#4427: hGetBuf sometimes reads fewer bytes than required
------------------------+---------------------------------------------------
    Reporter:  rl       |       Owner:                             
        Type:  bug      |      Status:  new                        
    Priority:  normal   |   Component:  libraries/base             
     Version:  7.1      |    Keywords:                             
    Testcase:           |   Blockedby:                             
          Os:  Windows  |    Blocking:                             
Architecture:  x86      |     Failure:  Incorrect result at runtime
------------------------+---------------------------------------------------
 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`.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4427>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list