Commit 33ed16bd authored by Merijn Verstraaten's avatar Merijn Verstraaten Committed by thoughtpolice
Browse files

*Really* RTS crash due to bad coercion.

Previous commit only moved the coercion mistake to a different
architecture (i.e. underflow could still occur on platforms where Int
is smaller than CInt). This patch should definitively deal with all
possible combinations.
Signed-off-by: thoughtpolice's avatarAustin Seipp <>
parent 00e04e81
...@@ -121,9 +121,23 @@ poll p mtout f = do ...@@ -121,9 +121,23 @@ poll p mtout f = do
then c_pollLoop ptr len (fromIntegral (tout - maxPollTimeout)) then c_pollLoop ptr len (fromIntegral (tout - maxPollTimeout))
else return result else return result
-- Timeout of c_poll is limited by max value of CInt -- We need to account for 3 cases:
-- 1. Int and CInt are of equal size.
-- 2. Int is larger than CInt
-- 3. Int is smaller than CInt
-- In case 1, the value of maxPollTimeout will be the maxBound of Int.
-- In case 2, the value of maxPollTimeout will be the maxBound of CInt,
-- which is the largest value accepted by c_poll. This will result in
-- c_pollLoop recursing if the provided timeout is larger.
-- In case 3, "fromIntegral (maxBound :: CInt) :: Int" wil result in a
-- negative Int, max will thus return maxBound :: Int. Since poll doesn't
-- accept values bigger than maxBound :: Int and CInt is larger than Int,
-- there is no problem converting Int to CInt for the c_poll call.
maxPollTimeout :: Int maxPollTimeout :: Int
maxPollTimeout = fromIntegral (maxBound :: CInt) maxPollTimeout = max maxBound (fromIntegral (maxBound :: CInt))
fromTimeout :: E.Timeout -> Int fromTimeout :: E.Timeout -> Int
fromTimeout E.Forever = -1 fromTimeout E.Forever = -1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment