Skip to content

Commit 807e3a4

Browse files
authored
Fix UB on 32 bit platforms (#413)
1 parent 63ec59a commit 807e3a4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Data/HashMap/Internal.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ import Control.DeepSeq (NFData (..), NFData1 (..), NFData2 (..))
144144
import Control.Monad.ST (ST, runST)
145145
import Data.Bifoldable (Bifoldable (..))
146146
import Data.Bits (complement, popCount, unsafeShiftL,
147-
unsafeShiftR, (.&.), (.|.), countTrailingZeros)
147+
unsafeShiftR, (.&.), (.|.), countTrailingZeros, shiftL)
148148
import Data.Coerce (coerce)
149149
import Data.Data (Constr, Data (..), DataType)
150150
import Data.Functor.Classes (Eq1 (..), Eq2 (..), Ord1 (..), Ord2 (..),
@@ -2257,7 +2257,9 @@ index w s = fromIntegral $ unsafeShiftR w s .&. subkeyMask
22572257

22582258
-- | A bitmask with the 'bitsPerSubkey' least significant bits set.
22592259
fullNodeMask :: Bitmap
2260-
fullNodeMask = complement (complement 0 `unsafeShiftL` maxChildren)
2260+
-- This needs to use 'shiftL' instead of 'unsafeShiftL', to avoid UB.
2261+
-- See issue #412.
2262+
fullNodeMask = complement (complement 0 `shiftL` maxChildren)
22612263
{-# INLINE fullNodeMask #-}
22622264

22632265
-- | Check if two the two arguments are the same value. N.B. This

0 commit comments

Comments
 (0)