aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2017-05-10 18:19:41 +0800
committerGitHub <noreply@github.com>2017-05-10 18:19:41 +0800
commit2ddf5a19c3a06978edff2c8ba0aaf5df3528204a (patch)
tree8a4b6f0ae35ee772702912050fd252b9e360c482 /Objects/sliceobject.c
parentbpo-30298: Weaken the condition of deprecation warnings for inline modifiers.... (diff)
downloadcpython-2ddf5a19c3a06978edff2c8ba0aaf5df3528204a.tar.gz
cpython-2ddf5a19c3a06978edff2c8ba0aaf5df3528204a.tar.bz2
cpython-2ddf5a19c3a06978edff2c8ba0aaf5df3528204a.zip
bpo-30281: Fix the default value for stop in PySlice_Unpack() (#1480)
Diffstat (limited to 'Objects/sliceobject.c')
-rw-r--r--Objects/sliceobject.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index ebc44642fe..4263737e41 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 */
+ Py_BUILD_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;
}