Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebc793d

Browse files
ZackerySpytzserhiy-storchaka
authored andcommitted
bpo-33989: Ensure that ms.key_compare is always initialized in list_sort_impl(). (GH-8710)
1 parent ef1b88b commit ebc793d

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a possible crash in :meth:`list.sort` when sorting objects with
2+
``ob_type->tp_richcompare == NULL``. Patch by Zackery Spytz.

Objects/listobject.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,9 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
23342334
else if ((ms.key_richcompare = key_type->tp_richcompare) != NULL) {
23352335
ms.key_compare = unsafe_object_compare;
23362336
}
2337+
else {
2338+
ms.key_compare = safe_object_compare;
2339+
}
23372340
}
23382341
else {
23392342
ms.key_compare = safe_object_compare;

0 commit comments

Comments
 (0)