[commit: packages/array] master: Fix overflow check (6e110fe)
git at git.haskell.org
git at git.haskell.org
Tue Dec 27 17:44:46 UTC 2016
Repository : ssh://git@git.haskell.org/array
On branch : master
Link : http://git.haskell.org/packages/array.git/commitdiff/6e110fe4193472c2e47aa0563362f95dd8bca37b
>---------------------------------------------------------------
commit 6e110fe4193472c2e47aa0563362f95dd8bca37b
Author: Ben Gamari <ben at smart-cactus.org>
Date: Mon Dec 26 13:13:26 2016 -0500
Fix overflow check
As akio points out, the fix to #229 which I authored previously was blatantly
wrong.
>---------------------------------------------------------------
6e110fe4193472c2e47aa0563362f95dd8bca37b
Data/Array/Base.hs | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/Data/Array/Base.hs b/Data/Array/Base.hs
index c88e272..43963eb 100644
--- a/Data/Array/Base.hs
+++ b/Data/Array/Base.hs
@@ -32,7 +32,7 @@ import GHC.Arr ( STArray )
import qualified GHC.Arr as Arr
import qualified GHC.Arr as ArrST
import GHC.ST ( ST(..), runST )
-import GHC.Base ( IO(..) )
+import GHC.Base ( IO(..), divInt# )
import GHC.Exts
import GHC.Ptr ( nullPtr, nullFunPtr )
import GHC.Stable ( StablePtr(..) )
@@ -1370,10 +1370,12 @@ fLOAT_SCALE n# = safe_scale scale# n# where !(I# scale#) = SIZEOF_HSFLOAT
safe_scale :: Int# -> Int# -> Int#
safe_scale scale# n#
- | isTrue# (res# >=# n#) = res#
- | otherwise = error "Data.Array.Base.safe_scale: Overflow"
+ | not overflow = res#
+ | otherwise = error "Data.Array.Base.safe_scale: Overflow"
where
!res# = scale# *# n#
+ !overflow = isTrue# (maxN# `divInt#` scale# <# n#)
+ !(I# maxN#) = maxBound
bOOL_INDEX :: Int# -> Int#
More information about the ghc-commits
mailing list