summaryrefslogtreecommitdiff
path: root/libraries/base/Data/Bits.hs
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2015-10-06 19:30:50 +0200
committerBen Gamari <ben@smart-cactus.org>2015-10-07 08:49:22 +0200
commitea4df12f7f3fc4d1d2af335804b8ec893f45550c (patch)
treea160f64dc2808fd4a40c1bbea211885f8c700a66 /libraries/base/Data/Bits.hs
parent36811bfd3bd981d3cd3cc7280e1a815ba1ed42e9 (diff)
downloadhaskell-ea4df12f7f3fc4d1d2af335804b8ec893f45550c.tar.gz
Ensure shiftL/shiftR arguments aren't negative
Fixes #10571.
Diffstat (limited to 'libraries/base/Data/Bits.hs')
-rw-r--r--libraries/base/Data/Bits.hs8
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