diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2010-04-06 16:46:09 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2010-04-06 16:46:09 (GMT) |
commit | 3ec9b942b5536e3fc597a065851750e01025b6f1 (patch) | |
tree | 991fce0269facbc6ffa43039be076b306a945c13 /Objects/longobject.c | |
parent | 72ec2e2bdf4a861b85ed7e4b038b134d8b4e4ea4 (diff) | |
download | cpython-3ec9b942b5536e3fc597a065851750e01025b6f1.zip cpython-3ec9b942b5536e3fc597a065851750e01025b6f1.tar.gz cpython-3ec9b942b5536e3fc597a065851750e01025b6f1.tar.bz2 |
Issue #8259: Get rid of 'outrageous left shift count' error when
left-shifting an integer by more than 2**31 on a 64-bit machine. Also
convert shift counts to a Py_ssize_t instead of a C long.
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r-- | Objects/longobject.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 4290f4e..0e6e4e3 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -3614,8 +3614,7 @@ long_rshift(PyLongObject *v, PyLongObject *w) { PyLongObject *a, *b; PyLongObject *z = NULL; - long shiftby; - Py_ssize_t newsize, wordshift, loshift, hishift, i, j; + Py_ssize_t shiftby, newsize, wordshift, loshift, hishift, i, j; digit lomask, himask; CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b); @@ -3634,8 +3633,7 @@ long_rshift(PyLongObject *v, PyLongObject *w) Py_DECREF(a2); } else { - - shiftby = PyLong_AsLong((PyObject *)b); + shiftby = PyLong_AsSsize_t((PyObject *)b); if (shiftby == -1L && PyErr_Occurred()) goto rshift_error; if (shiftby < 0) { @@ -3681,27 +3679,21 @@ long_lshift(PyObject *v, PyObject *w) /* This version due to Tim Peters */ PyLongObject *a, *b; PyLongObject *z = NULL; - long shiftby; - Py_ssize_t oldsize, newsize, wordshift, remshift, i, j; + Py_ssize_t shiftby, oldsize, newsize, wordshift, remshift, i, j; twodigits accum; CONVERT_BINOP(v, w, &a, &b); - shiftby = PyLong_AsLong((PyObject *)b); + shiftby = PyLong_AsSsize_t((PyObject *)b); if (shiftby == -1L && PyErr_Occurred()) goto lshift_error; if (shiftby < 0) { PyErr_SetString(PyExc_ValueError, "negative shift count"); goto lshift_error; } - if ((long)(int)shiftby != shiftby) { - PyErr_SetString(PyExc_ValueError, - "outrageous left shift count"); - goto lshift_error; - } /* wordshift, remshift = divmod(shiftby, PyLong_SHIFT) */ - wordshift = (int)shiftby / PyLong_SHIFT; - remshift = (int)shiftby - wordshift * PyLong_SHIFT; + wordshift = shiftby / PyLong_SHIFT; + remshift = shiftby - wordshift * PyLong_SHIFT; oldsize = ABS(a->ob_size); newsize = oldsize + wordshift; |