diff options
author | Ben Gamari <ben@smart-cactus.org> | 2015-10-06 19:30:50 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-10-07 08:49:22 +0200 |
commit | ea4df12f7f3fc4d1d2af335804b8ec893f45550c (patch) | |
tree | a160f64dc2808fd4a40c1bbea211885f8c700a66 | |
parent | 36811bfd3bd981d3cd3cc7280e1a815ba1ed42e9 (diff) | |
download | haskell-ea4df12f7f3fc4d1d2af335804b8ec893f45550c.tar.gz |
Ensure shiftL/shiftR arguments aren't negative
Fixes #10571.
-rw-r--r-- | libraries/base/Data/Bits.hs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/libraries/base/Data/Bits.hs b/libraries/base/Data/Bits.hs index 84b1c031b1..38025f877c 100644 --- a/libraries/base/Data/Bits.hs +++ b/libraries/base/Data/Bits.hs @@ -515,8 +515,12 @@ instance Bits Integer where complement = complementInteger shift x i@(I# i#) | i >= 0 = shiftLInteger x i# | otherwise = shiftRInteger x (negateInt# i#) - shiftL x (I# i#) = shiftLInteger x i# - shiftR x (I# i#) = shiftRInteger x i# + shiftL x i@(I# i#) + | i < 0 = error "Bits.shiftL(Integer): negative shift" + | otherwise = shiftLInteger x i# + shiftR x i@(I# i#) + | i < 0 = error "Bits.shiftR(Integer): negative shift" + | otherwise = shiftRInteger x i# testBit x (I# i) = testBitInteger x i |