Forked from
Glasgow Haskell Compiler / GHC
31868 commits behind, 249 commits ahead of the upstream repository.
-
rwbarton authored
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 (cherry picked from commit db641808) Conflicts: testsuite/.gitignore
rwbarton authoredSummary: 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 (cherry picked from commit db641808) Conflicts: testsuite/.gitignore
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
overflow2.hs 663 B
{-# 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)