Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.5] bpo-30281: Fix the default value for stop in PySlice_Unpack() #1530

Merged
merged 2 commits into from
May 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Objects/sliceobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ PySlice_Unpack(PyObject *_r,
PySliceObject *r = (PySliceObject*)_r;
/* this is harder to get right than you might think */

assert(PY_SSIZE_T_MIN + 1 <= -PY_SSIZE_T_MAX);

if (r->step == Py_None) {
*step = 1;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -5095,7 +5095,7 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
/* 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
Expand Down