]> granicus.if.org Git - python/commitdiff
Use a better check for overflow from a<<b.
authorGuido van Rossum <guido@python.org>
Sun, 11 Aug 2002 14:04:13 +0000 (14:04 +0000)
committerGuido van Rossum <guido@python.org>
Sun, 11 Aug 2002 14:04:13 +0000 (14:04 +0000)
Objects/intobject.c

index 728f798a5b66602f2ac584751307806cb58ff488..40f38ba343beae94979e489689246f54ab22b914 100644 (file)
@@ -675,13 +675,15 @@ int_lshift(PyIntObject *v, PyIntObject *w)
                        return NULL;
                return PyInt_FromLong(0L);
        }
-       c = (long)((unsigned long)a << b);
-       if ((c >> b) != a || (c < 0 && a > 0)) {
+       c = a < 0 ? ~a : a;
+       c >>= LONG_BIT - 1 - b;
+       if (c) {
                if (PyErr_Warn(PyExc_DeprecationWarning,
                               "x<<y losing bits or changing sign "
                               "will return a long in Python 2.4 and up") < 0)
                        return NULL;
        }
+       c = (long)((unsigned long)a << b);
        return PyInt_FromLong(c);
 }