diff options
author | Reid Barton <rwbarton@gmail.com> | 2014-07-01 10:20:31 -0400 |
---|---|---|
committer | Reid Barton <rwbarton@gmail.com> | 2014-07-01 10:20:31 -0400 |
commit | db64180896b395283f443d66a308048c605b217d (patch) | |
tree | 7520205f139aa715c87f04f5534da0e5b44db2ce /testsuite/tests/rts/overflow2.hs | |
parent | 5f3c5384df59717ca8013c5df8d1f65692867825 (diff) | |
download | haskell-db64180896b395283f443d66a308048c605b217d.tar.gz |
Check for integer overflow in allocate() (#9172)
Summary: Check for integer overflow in allocate() (#9172)
Test Plan: validate
Reviewers: austin
Reviewed By: austin
Subscribers: simonmar, relrod, carter
Differential Revision: https://phabricator.haskell.org/D36
Diffstat (limited to 'testsuite/tests/rts/overflow2.hs')
-rw-r--r-- | testsuite/tests/rts/overflow2.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/testsuite/tests/rts/overflow2.hs b/testsuite/tests/rts/overflow2.hs new file mode 100644 index 0000000000..ac72158f45 --- /dev/null +++ b/testsuite/tests/rts/overflow2.hs @@ -0,0 +1,20 @@ +{-# LANGUAGE ForeignFunctionInterface #-} +module Main where + +import Foreign + +-- Test allocate(), the easy way. +data Cap = Cap +foreign import ccall "rts_unsafeGetMyCapability" myCapability :: IO (Ptr Cap) +foreign import ccall "allocate" allocate :: Ptr Cap -> Word -> IO (Ptr ()) + +-- Number of words n such that n * sizeof(W_) exactly overflows a word +-- (2^30 on a 32-bit system, 2^61 on a 64-bit system) +overflowWordCount :: Word +overflowWordCount = fromInteger $ + (fromIntegral (maxBound :: Word) + 1) `div` + fromIntegral (sizeOf (undefined :: Word)) + +main = do + cap <- myCapability + allocate cap (overflowWordCount - 1) |