Skip to content
Browse files

Ensure hGetBufSome does not cause potentially blocking reads (#5843)

When there is data in a handle buffer, never fetch more than the
available number of elements, since that can cause a blocking read on
  • Loading branch information...
1 parent a360b6b commit 370fc0b455f6a03283fbd5c0baa5d08d9115379d @pcapriotti pcapriotti committed Mar 27, 2012
Showing with 2 additions and 1 deletion.
  1. +2 −1 GHC/IO/Handle/Text.hs
3 GHC/IO/Handle/Text.hs
@@ -889,7 +889,8 @@ hGetBufSome h ptr count
-- that bufReadNBNonEmpty will not
-- issue another read.
- bufReadNBNonEmpty h_ buf (castPtr ptr) 0 count
+ let count' = min count (bufferElems buf)
+ in bufReadNBNonEmpty h_ buf (castPtr ptr) 0 count'
haFD :: Handle__ -> FD
haFD h_@Handle__{..} =

0 comments on commit 370fc0b

Please sign in to comment.
Something went wrong with that request. Please try again.