…nctions with asserts
The actual overflow can never happen because of the following:
* The size of a list can't be greater than PY_SSIZE_T_MAX / sizeof(PyObject*).
* The size of a pointer on all supported plaftorms is at least 4 bytes.
* ofs is positive and less than the list size at the beginning of each iteration.
https://bugs.python.org/issue35091
while (ofs < maxofs) {
IFLT(a[ofs], key) {
lastofs = ofs;
+ assert(ofs <= (PY_SSIZE_T_MAX - 1) / 2);
ofs = (ofs << 1) + 1;
- if (ofs <= 0) /* int overflow */
- ofs = maxofs;
}
else /* key <= a[hint + ofs] */
break;
break;
/* key <= a[hint - ofs] */
lastofs = ofs;
+ assert(ofs <= (PY_SSIZE_T_MAX - 1) / 2);
ofs = (ofs << 1) + 1;
- if (ofs <= 0) /* int overflow */
- ofs = maxofs;
}
if (ofs > maxofs)
ofs = maxofs;
while (ofs < maxofs) {
IFLT(key, *(a-ofs)) {
lastofs = ofs;
+ assert(ofs <= (PY_SSIZE_T_MAX - 1) / 2);
ofs = (ofs << 1) + 1;
- if (ofs <= 0) /* int overflow */
- ofs = maxofs;
}
else /* a[hint - ofs] <= key */
break;
break;
/* a[hint + ofs] <= key */
lastofs = ofs;
+ assert(ofs <= (PY_SSIZE_T_MAX - 1) / 2);
ofs = (ofs << 1) + 1;
- if (ofs <= 0) /* int overflow */
- ofs = maxofs;
}
if (ofs > maxofs)
ofs = maxofs;