[GHC] #14262: fdReady cannot wait more than 49 days
GHC
ghc-devs at haskell.org
Fri Nov 24 21:29:19 UTC 2017
#14262: fdReady cannot wait more than 49 days
-------------------------------------+-------------------------------------
Reporter: nh2 | Owner: (none)
Type: bug | Status: closed
Priority: normal | Milestone: 8.4.1
Component: Compiler | Version: 8.2.1
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture: x86_64
| (amd64)
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #8684, #13497, | Differential Rev(s):
#14267 |
Wiki Page: |
-------------------------------------+-------------------------------------
Changes (by bgamari):
* status: new => closed
* resolution: => fixed
* milestone: => 8.4.1
Old description:
> {{{
> 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.
New description:
{{{#!hs
import System.IO
hWaitForInput stdin 4294968296
}}}
This code waits for 1 second instead of 49.something days.
The culprit:
{{{#!hs
hWaitForInput :: Handle -> Int -> IO Bool
fdReady(..., int msecs, ...)
}}}
Haskell `Int` is usally 64 bits. C `int` is usually 32 bits.
Called here:
{{{#!hs
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.
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14262#comment:7>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list