mirror of
https://github.com/python/cpython.git
synced 2025-10-19 13:18:16 +00:00
Use a better check for overflow from a<<b.
This commit is contained in:
parent
cc8764ca9d
commit
643d59cbd6
1 changed files with 4 additions and 2 deletions
|
@ -675,13 +675,15 @@ int_lshift(PyIntObject *v, PyIntObject *w)
|
||||||
return NULL;
|
return NULL;
|
||||||
return PyInt_FromLong(0L);
|
return PyInt_FromLong(0L);
|
||||||
}
|
}
|
||||||
c = (long)((unsigned long)a << b);
|
c = a < 0 ? ~a : a;
|
||||||
if ((c >> b) != a || (c < 0 && a > 0)) {
|
c >>= LONG_BIT - 1 - b;
|
||||||
|
if (c) {
|
||||||
if (PyErr_Warn(PyExc_DeprecationWarning,
|
if (PyErr_Warn(PyExc_DeprecationWarning,
|
||||||
"x<<y losing bits or changing sign "
|
"x<<y losing bits or changing sign "
|
||||||
"will return a long in Python 2.4 and up") < 0)
|
"will return a long in Python 2.4 and up") < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
c = (long)((unsigned long)a << b);
|
||||||
return PyInt_FromLong(c);
|
return PyInt_FromLong(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue