[commit: ghc] master: Ensure shiftL/shiftR arguments aren't negative (ea4df12)

git at git.haskell.org git at git.haskell.org
Wed Oct 7 06:47:04 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/ea4df12f7f3fc4d1d2af335804b8ec893f45550c/ghc

>---------------------------------------------------------------

commit ea4df12f7f3fc4d1d2af335804b8ec893f45550c
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Tue Oct 6 19:30:50 2015 +0200

    Ensure shiftL/shiftR arguments aren't negative
    
    Fixes #10571.


>---------------------------------------------------------------

ea4df12f7f3fc4d1d2af335804b8ec893f45550c
 libraries/base/Data/Bits.hs | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libraries/base/Data/Bits.hs b/libraries/base/Data/Bits.hs
index 84b1c03..38025f8 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
 



More information about the ghc-commits mailing list