fdReady cannot wait more than 49 days
import System.IO
hWaitForInput stdin 4294968296
This code waits for 1 second instead of 49.something days.
The culprit:
hWaitForInput :: Handle -> Int -> IO Bool
fdReady(..., int msecs, ...)
Haskell Int
is usally 64 bits. C int
is usually 32 bits.
Called here:
ready :: FD -> Bool -> Int -> IO Bool
ready fd write msecs = do
r <- throwErrnoIfMinus1Retry "GHC.IO.FD.ready" $
fdReady (fdFD fd) (fromIntegral $ fromEnum $ write)
(fromIntegral msecs)
foreign import ccall safe "fdReady"
fdReady :: CInt -> CInt -> CInt -> CInt -> IO CInt
We fromIntegral
Int
to CInt
(== Int32
), overflowing.