gh-92839: fixed typo in _bisectmodule.c (line 131) (#92849)

This commit is contained in:
oda-gitso 2022-05-29 01:08:06 +07:00 committed by GitHub
parent dec1e9346d
commit 7fa9b7daa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -257,6 +257,12 @@ class TestBisect:
target
)
def test_insort_keynotNone(self):
x = []
y = {"a": 2, "b": 1}
for f in (self.module.insort_left, self.module.insort_right):
self.assertRaises(TypeError, f, x, y, key = "b")
class TestBisectPython(TestBisect, unittest.TestCase):
module = py_bisect

View File

@ -0,0 +1 @@
Fixed crash resulting from calling bisect.insort() or bisect.insort_left() with the key argument not equal to None.

View File

@ -128,7 +128,7 @@ _bisect_insort_right_impl(PyObject *module, PyObject *a, PyObject *x,
index = internal_bisect_right(a, x, lo, hi, key);
} else {
key_x = PyObject_CallOneArg(key, x);
if (x == NULL) {
if (key_x == NULL) {
return NULL;
}
index = internal_bisect_right(a, key_x, lo, hi, key);
@ -256,7 +256,7 @@ _bisect_insort_left_impl(PyObject *module, PyObject *a, PyObject *x,
index = internal_bisect_left(a, x, lo, hi, key);
} else {
key_x = PyObject_CallOneArg(key, x);
if (x == NULL) {
if (key_x == NULL) {
return NULL;
}
index = internal_bisect_left(a, key_x, lo, hi, key);