summaryrefslogtreecommitdiff
path: root/libraries/integer-gmp/src
diff options
context:
space:
mode:
authorSimon Jakobi <simon.jakobi@gmail.com>2019-06-04 02:54:35 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-06-07 10:25:16 -0400
commitbe63d2996308c77f8a0a44592074c98f66a80e93 (patch)
treea909f8ac110302edb84e70c4c7b2073209588037 /libraries/integer-gmp/src
parent9bb58799d2ce58f6aef772df79ad26210403aded (diff)
downloadhaskell-be63d2996308c77f8a0a44592074c98f66a80e93.tar.gz
Fix isValidNatural: The BigNat in NatJ# must have at least 2 limbs
Previously the `integer-gmp` variant of `isValidNatural` would fail to detect values `<= maxBound::Word` that were incorrectly encoded using the `NatJ#` constructor.
Diffstat (limited to 'libraries/integer-gmp/src')
-rw-r--r--libraries/integer-gmp/src/GHC/Integer/Type.hs2
1 files changed, 2 insertions, 0 deletions
diff --git a/libraries/integer-gmp/src/GHC/Integer/Type.hs b/libraries/integer-gmp/src/GHC/Integer/Type.hs
index 521cd95a25..14bdb57ffd 100644
--- a/libraries/integer-gmp/src/GHC/Integer/Type.hs
+++ b/libraries/integer-gmp/src/GHC/Integer/Type.hs
@@ -1778,6 +1778,8 @@ foreign import ccall unsafe "gmp.h __gmpn_popcount"
-- BigNat-wrapped ByteArray#-primops
-- | Return number of limbs contained in 'BigNat'.
+--
+-- The result is always @>= 1@ since even zero is encoded with 1 limb.
sizeofBigNat# :: BigNat -> GmpSize#
sizeofBigNat# (BN# x#)
= sizeofByteArray# x# `uncheckedIShiftRL#` GMP_LIMB_SHIFT#