diff options
| author | Xiang Zhang <angwerzx@126.com> | 2017-05-10 11:20:28 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-10 11:20:28 (GMT) |
| commit | 05469fa1c05acf55bdca05db21822ecdd7f6487a (patch) | |
| tree | 264e99b1b8d4f03b10f3667c597e8d9c9d16d465 /Objects/sliceobject.c | |
| parent | 88321413a719fa61eab2b9d33bc6a68826f562d2 (diff) | |
| download | cpython-05469fa1c05acf55bdca05db21822ecdd7f6487a.zip cpython-05469fa1c05acf55bdca05db21822ecdd7f6487a.tar.gz cpython-05469fa1c05acf55bdca05db21822ecdd7f6487a.tar.bz2 | |
bpo-30281: Fix the default value for stop in PySlice_Unpack() (#1531) (#1480)
Diffstat (limited to 'Objects/sliceobject.c')
| -rw-r--r-- | Objects/sliceobject.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index 64be927..c66e057 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -137,6 +137,8 @@ _PySlice_Unpack(PyObject *_r, PySliceObject *r = (PySliceObject *)_r; /* this is harder to get right than you might think */ + assert(PY_SSIZE_T_MIN + 1 <= -PY_SSIZE_T_MAX); + if (r->step == Py_None) { *step = 1; } @@ -157,14 +159,14 @@ _PySlice_Unpack(PyObject *_r, } if (r->start == Py_None) { - *start = *step < 0 ? PY_SSIZE_T_MAX-1 : 0;; + *start = *step < 0 ? PY_SSIZE_T_MAX : 0; } else { if (!_PyEval_SliceIndex(r->start, start)) return -1; } if (r->stop == Py_None) { - *stop = *step < 0 ? -PY_SSIZE_T_MAX : PY_SSIZE_T_MAX; + *stop = *step < 0 ? PY_SSIZE_T_MIN : PY_SSIZE_T_MAX; } else { if (!_PyEval_SliceIndex(r->stop, stop)) return -1; @@ -198,7 +200,7 @@ _PySlice_AdjustIndices(Py_ssize_t length, *stop = (step < 0) ? -1 : 0; } } - else if (*stop >= length) { + else if (*stop >= length) { *stop = (step < 0) ? length - 1 : length; } |
