mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
Issue #6985: number of range() items should be constrained to lie
in a Py_ssize_t, not an int.
This commit is contained in:
parent
91c12ebc3d
commit
3dc254181a
1 changed files with 4 additions and 4 deletions
|
@ -1754,7 +1754,7 @@ handle_range_longs(PyObject *self, PyObject *args)
|
||||||
PyObject *curnum = NULL;
|
PyObject *curnum = NULL;
|
||||||
PyObject *v = NULL;
|
PyObject *v = NULL;
|
||||||
long bign;
|
long bign;
|
||||||
int i, n;
|
Py_ssize_t i, n;
|
||||||
int cmp_result;
|
int cmp_result;
|
||||||
|
|
||||||
PyObject *zero = PyLong_FromLong(0);
|
PyObject *zero = PyLong_FromLong(0);
|
||||||
|
@ -1834,7 +1834,7 @@ handle_range_longs(PyObject *self, PyObject *args)
|
||||||
Py_DECREF(neg_istep);
|
Py_DECREF(neg_istep);
|
||||||
}
|
}
|
||||||
|
|
||||||
n = (int)bign;
|
n = (Py_ssize_t)bign;
|
||||||
if (bign < 0 || (long)n != bign) {
|
if (bign < 0 || (long)n != bign) {
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
"range() result has too many items");
|
"range() result has too many items");
|
||||||
|
@ -1914,7 +1914,7 @@ builtin_range(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
long ilow = 0, ihigh = 0, istep = 1;
|
long ilow = 0, ihigh = 0, istep = 1;
|
||||||
long bign;
|
long bign;
|
||||||
int i, n;
|
Py_ssize_t i, n;
|
||||||
|
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
|
|
||||||
|
@ -1943,7 +1943,7 @@ builtin_range(PyObject *self, PyObject *args)
|
||||||
bign = get_len_of_range(ilow, ihigh, istep);
|
bign = get_len_of_range(ilow, ihigh, istep);
|
||||||
else
|
else
|
||||||
bign = get_len_of_range(ihigh, ilow, -istep);
|
bign = get_len_of_range(ihigh, ilow, -istep);
|
||||||
n = (int)bign;
|
n = (Py_ssize_t)bign;
|
||||||
if (bign < 0 || (long)n != bign) {
|
if (bign < 0 || (long)n != bign) {
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
"range() result has too many items");
|
"range() result has too many items");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue