C API
-----
+- bpo-30255: PySlice_GetIndicesEx now clips the step to
+ [-PY_SSIZE_T_MAX, PY_SSIZE_T_MAX] instead of
+ [-PY_SSIZE_T_MAX-1, PY_SSIZE_T_MAX]. This makes it safe to do "step = -step"
+ when reversing a slice.
+
- Issue #26476: Fixed compilation error when use PyErr_BadInternalCall() in C++.
Patch by Jeroen Demeyer.
"slice step cannot be zero");
return -1;
}
+ /* Here *step might be -PY_SSIZE_T_MAX-1; in this case we replace it
+ * with -PY_SSIZE_T_MAX. This doesn't affect the semantics, and it
+ * guards against later undefined behaviour resulting from code that
+ * does "step = -step" as part of a slice reversal.
+ */
+ if (*step < -PY_SSIZE_T_MAX)
+ *step = -PY_SSIZE_T_MAX;
}
if (r->start == Py_None) {