]> granicus.if.org Git - python/commitdiff
bpo-30281: Fix the default value for stop in PySlice_Unpack() (#1480) (#1529)
authorXiang Zhang <angwerzx@126.com>
Wed, 10 May 2017 11:00:15 +0000 (19:00 +0800)
committerGitHub <noreply@github.com>
Wed, 10 May 2017 11:00:15 +0000 (19:00 +0800)
Objects/sliceobject.c
Python/ceval.c

index 6a690213d1451867d29e571b9a58b4202ed0df29..4e4b32d32441a8d05752b2aab876946a645d8b38 100644 (file)
@@ -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;
     }
 
index bce86ab12cf2fbeece03787ebfc1473cda6819b1..5dc0444a1acf5c9eeaa2a7a239d8a89378693387 100644 (file)
@@ -5071,7 +5071,7 @@ do_call_core(PyObject *func, PyObject *callargs, PyObject *kwdict)
 /* 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