Author: Tim Felgentreff <[email protected]>
Branch: 
Changeset: r263:5c6f91a09689
Date: 2013-04-12 15:59 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/5c6f91a09689/

Log:    make sure we don't left shift by more than wordsize

diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -219,11 +219,15 @@
 # #bitShift: -- return the shifted value
 @expose_primitive(BIT_SHIFT, unwrap_spec=[object, int])
 def func(interp, s_frame, receiver, argument):
-    # overflow-checking done in lshift implementations
-    if argument > 0:
-        return receiver.lshift(interp.space, argument)
+    from rpython.rlib.rarithmetic import LONG_BIT
+    if -LONG_BIT < argument < LONG_BIT:
+        # overflow-checking done in lshift implementations
+        if argument > 0:
+            return receiver.lshift(interp.space, argument)
+        else:
+            return receiver.rshift(interp.space, -argument)
     else:
-        return receiver.rshift(interp.space, -argument)
+        raise PrimitiveFailedError()
 
 # ___________________________________________________________________________
 # Float Primitives
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to