From 639e295650a51894412c9d976958792010d3bcf8 Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Wed, 10 May 2017 19:11:09 +0800 Subject: [PATCH] =?utf8?q?bpo-30281:=20Fix=20the=20default=20value=20for?= =?utf8?q?=20stop=20in=20PySlice=5FUnpack()=20(#1530)=20(#1480=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Objects/sliceobject.c | 8 +++++--- Python/ceval.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index 6a690213d1..32599476bb 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -197,6 +197,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; } @@ -217,14 +219,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; @@ -258,7 +260,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; } diff --git a/Python/ceval.c b/Python/ceval.c index 3070a90b43..47c5eff64f 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5095,7 +5095,7 @@ ext_call_fail: /* Extract a slice index from a PyLong or an object with the nb_index slot defined, and store in *pi. Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX, - and silently boost values less than -PY_SSIZE_T_MAX-1 to -PY_SSIZE_T_MAX-1. + and silently boost values less than PY_SSIZE_T_MIN to PY_SSIZE_T_MIN. Return 0 on error, 1 on success. */ int -- 2.50.1