Skip to content

Commit b5c7a66

Browse files
committed
Fix bounds check of hi argument in bisect_left|right functions
1 parent 782217f commit b5c7a66

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Modify the check of ``hi`` argument in ``internal_bisect_left`` and
2+
``internal_bisect_right`` so that negative numbers are not allowed
3+
to be passed.

Modules/_bisectmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ internal_bisect_right(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t
6161
PyErr_SetString(PyExc_ValueError, "lo must be non-negative");
6262
return -1;
6363
}
64-
if (hi == -1) {
64+
if (hi < 0) {
6565
hi = PySequence_Size(list);
6666
if (hi < 0)
6767
return -1;
@@ -245,7 +245,7 @@ internal_bisect_left(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t h
245245
PyErr_SetString(PyExc_ValueError, "lo must be non-negative");
246246
return -1;
247247
}
248-
if (hi == -1) {
248+
if (hi < 0) {
249249
hi = PySequence_Size(list);
250250
if (hi < 0)
251251
return -1;

0 commit comments

Comments
 (0)