Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2ddf5a1

Browse filesBrowse files
authored
bpo-30281: Fix the default value for stop in PySlice_Unpack() (#1480)
1 parent 305ccbe commit 2ddf5a1
Copy full SHA for 2ddf5a1

File tree

3 files changed

+7
-5
lines changed
Filter options

3 files changed

+7
-5
lines changed

‎Doc/c-api/slice.rst

Copy file name to clipboardExpand all lines: Doc/c-api/slice.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Slice Objects
7575
Extract the start, stop and step data members from a slice object as
7676
C integers. Silently reduce values larger than ``PY_SSIZE_T_MAX`` to
7777
``PY_SSIZE_T_MAX``, silently boost the start and stop values less than
78-
``-PY_SSIZE_T_MAX-1`` to ``-PY_SSIZE_T_MAX-1``, and silently boost the step
78+
``PY_SSIZE_T_MIN`` to ``PY_SSIZE_T_MIN``, and silently boost the step
7979
values less than ``-PY_SSIZE_T_MAX`` to ``-PY_SSIZE_T_MAX``.
8080
8181
Return ``-1`` on error, ``0`` on success.

‎Objects/sliceobject.c

Copy file name to clipboardExpand all lines: Objects/sliceobject.c
+5-3Lines 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

Copy file name to clipboardExpand all lines: Python/ceval.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4889,7 +4889,7 @@ do_call_core(PyObject *func, PyObject *callargs, PyObject *kwdict)
48894889
/* Extract a slice index from a PyLong or an object with the
48904890
nb_index slot defined, and store in *pi.
48914891
Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX,
4892-
and silently boost values less than -PY_SSIZE_T_MAX-1 to -PY_SSIZE_T_MAX-1.
4892+
and silently boost values less than PY_SSIZE_T_MIN to PY_SSIZE_T_MIN.
48934893
Return 0 on error, 1 on success.
48944894
*/
48954895
int

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.