Opened 6 years ago

Closed 6 years ago

#5541 closed bug (invalid)

Data.Bits.setBit misbehaves on bad input

Reported by: nomeata Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.0.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime crash Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:



ghc -e 'Data.Bits.setBit 0 (2^36::Int) :: Integer'

seems to “work” (allocates lots of memory and keeps calculating), it mis-behaves with larger numbers:

$ ghc -e 'Data.Bits.setBit 0 (2^37::Int) :: Integer'
gmp: overflow in mpz type

If gmp cannot cope with that number, an exception should be raised, but not the whole process terminated.

Natuarlly, this is not a very critical bug.

Change History (2)

comment:1 Changed 6 years ago by

gmp itself calls abort() when trying to allocate too much. Is it sensible to install a handler for SIGABRT to transform it into a Haskell exception?

comment:2 Changed 6 years ago by igloo

Resolution: invalid
Status: newclosed

We've just been discussing this on IRC, and the conclusion is that we can't stop abort from terminating the process; from the abort manpage:

       If  the SIGABRT signal is ignored, or caught by a handler that returns,
       the abort() function will still terminate the process.  It does this by
       restoring the default disposition for SIGABRT and then raising the sig‐
       nal for a second time.
Note: See TracTickets for help on using tickets.