hGetBuf: fix a case of a short read being returned (#4427)
authorSimon Marlow <marlowsd@gmail.com>
Wed, 27 Oct 2010 14:43:24 +0000 (14:43 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Wed, 27 Oct 2010 14:43:24 +0000 (14:43 +0000)
GHC/IO/Handle/Text.hs

index ebb29c8..cf2541f 100644 (file)
@@ -861,7 +861,7 @@ bufReadEmpty h_@Handle__{..}
                 bufReadNonEmpty h_ buf' ptr so_far count
  where
   loop :: FD -> Int -> Int -> IO Int
-  loop fd off bytes | bytes <= 0 = return off
+  loop fd off bytes | bytes <= 0 = return (so_far + off)
   loop fd off bytes = do
     r <- RawIO.read (fd::FD) (ptr `plusPtr` off) (fromIntegral bytes)
     if r == 0