Skip to content

Commit 639e295

Browse files
authored
bpo-30281: Fix the default value for stop in PySlice_Unpack() (#1530) (#1480
1 parent 9721729 commit 639e295

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Objects/sliceobject.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ PySlice_Unpack(PyObject *_r,
197197
PySliceObject *r = (PySliceObject*)_r;
198198
/* this is harder to get right than you might think */
199199

200+
assert(PY_SSIZE_T_MIN + 1 <= -PY_SSIZE_T_MAX);
201+
200202
if (r->step == Py_None) {
201203
*step = 1;
202204
}
@@ -217,14 +219,14 @@ PySlice_Unpack(PyObject *_r,
217219
}
218220

219221
if (r->start == Py_None) {
220-
*start = *step < 0 ? PY_SSIZE_T_MAX-1 : 0;;
222+
*start = *step < 0 ? PY_SSIZE_T_MAX : 0;
221223
}
222224
else {
223225
if (!_PyEval_SliceIndex(r->start, start)) return -1;
224226
}
225227

226228
if (r->stop == Py_None) {
227-
*stop = *step < 0 ? -PY_SSIZE_T_MAX : PY_SSIZE_T_MAX;
229+
*stop = *step < 0 ? PY_SSIZE_T_MIN : PY_SSIZE_T_MAX;
228230
}
229231
else {
230232
if (!_PyEval_SliceIndex(r->stop, stop)) return -1;
@@ -258,7 +260,7 @@ PySlice_AdjustIndices(Py_ssize_t length,
258260
*stop = (step < 0) ? -1 : 0;
259261
}
260262
}
261-
else if (*stop >= length) {
263+
else if (*stop >= length) {
262264
*stop = (step < 0) ? length - 1 : length;
263265
}
264266

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5095,7 +5095,7 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
50955095
/* Extract a slice index from a PyLong or an object with the
50965096
nb_index slot defined, and store in *pi.
50975097
Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX,
5098-
and silently boost values less than -PY_SSIZE_T_MAX-1 to -PY_SSIZE_T_MAX-1.
5098+
and silently boost values less than PY_SSIZE_T_MIN to PY_SSIZE_T_MIN.
50995099
Return 0 on error, 1 on success.
51005100
*/
51015101
int

0 commit comments

Comments
 (0)