diff options
author | Guido van Rossum <guido@python.org> | 2002-08-11 14:04:13 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-08-11 14:04:13 (GMT) |
commit | 643d59cbd6f86516b083b958d76750b3626da3d6 (patch) | |
tree | 026dfbf6568d250b640f11833d631e38ae1c5d34 /Objects/intobject.c | |
parent | cc8764ca9dc3fceb9dc283163a89c9bb649b5392 (diff) | |
download | cpython-643d59cbd6f86516b083b958d76750b3626da3d6.zip cpython-643d59cbd6f86516b083b958d76750b3626da3d6.tar.gz cpython-643d59cbd6f86516b083b958d76750b3626da3d6.tar.bz2 |
Use a better check for overflow from a<<b.
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r-- | Objects/intobject.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index 728f798..40f38ba 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -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); } |