Skip to content

Commit 98b49a0

Browse files
authored
bpo-30281: Fix the default value for stop in PySlice_Unpack() (#1480) (#1529)
1 parent 81ed537 commit 98b49a0

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+
Py_BUILD_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
@@ -5071,7 +5071,7 @@ do_call_core(PyObject *func, PyObject *callargs, PyObject *kwdict)
50715071
/* Extract a slice index from a PyLong or an object with the
50725072
nb_index slot defined, and store in *pi.
50735073
Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX,
5074-
and silently boost values less than -PY_SSIZE_T_MAX-1 to -PY_SSIZE_T_MAX-1.
5074+
and silently boost values less than PY_SSIZE_T_MIN to PY_SSIZE_T_MIN.
50755075
Return 0 on error, 1 on success.
50765076
*/
50775077
int

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy