[commit: ghc] ghc-7.10: Ensure shiftL/shiftR arguments aren't negative (b29ad80)

git at git.haskell.org git at git.haskell.org
Thu Oct 22 15:09:45 UTC 2015


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

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/b29ad804074c2a27f0781448f817c9671a93dd77/ghc

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

commit b29ad804074c2a27f0781448f817c9671a93dd77
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.


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

b29ad804074c2a27f0781448f817c9671a93dd77
 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