Bug in hGetBufBA + hIsEOF

Simon Marlow simonmar at microsoft.com
Mon Dec 10 11:33:27 EST 2001


> Given a file "test" of size 2342.
> 
> The program "Bug.hs" behaves correctly (the result is
> "(2048,384)"), but when uncommenting the seemingly innocent
> line, the program behaves incorrectly (result is
> "(2048,2048)"), and the buffer is filled with garbage.
> 
> main =
>   do han <- openFile "test" ReadMode
>      arr <- stToIO (newCharArray (0,2048))
>      n1  <- hGetBufBA han arr 2048
>      --eof <- hIsEOF han
>      n2  <- hGetBufBA han arr 2048
>      print (n1,n2)
> 
> I am using solaris and GHC 5.02.1.

Thanks, that's a bug.  Workaround: hGetBufBA will only return a value
less than the specified count if EOF is reached, so you can detect EOF
that way.

Cheers,
	Simon




More information about the Glasgow-haskell-bugs mailing list