]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-92839: fixed typo in _bisectmodule.c (line 131) (GH-92849)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 28 May 2022 18:31:06 +0000 (11:31 -0700)
committerGitHub <noreply@github.com>
Sat, 28 May 2022 18:31:06 +0000 (11:31 -0700)
(cherry picked from commit 7fa9b7daa5a8bb5760724ac2d94f5298c60dc905)

Co-authored-by: oda-gitso <105083118+oda-gitso@users.noreply.github.com>
Lib/test/test_bisect.py
Misc/NEWS.d/next/Library/2022-05-16-14-35-39.gh-issue-92839.owSMyo.rst [new file with mode: 0644]
Modules/_bisectmodule.c

index 20f8b9d7c0aa870a1130b1131aaf1960a9cd7fe8..ba108221ebf4543b4b96526ec25425a4776d1809 100644 (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
 
diff --git a/Misc/NEWS.d/next/Library/2022-05-16-14-35-39.gh-issue-92839.owSMyo.rst b/Misc/NEWS.d/next/Library/2022-05-16-14-35-39.gh-issue-92839.owSMyo.rst
new file mode 100644 (file)
index 0000000..b425bd9
--- /dev/null
@@ -0,0 +1 @@
+Fixed crash resulting from calling bisect.insort() or bisect.insort_left() with the key argument not equal to None.
index 19e9cd2d46f10976f32cc58a25860b9ea2ddb12a..0caa92b2dc6e0244f11aae6d5ec471d16d36d201 100644 (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);