bpo-33989: Ensure that ms.key_compare is always initialized in list_s… · python/cpython@0e73ea2

File tree

2 files changed

lines changed

  • Misc/NEWS.d/next/Core and Builtins

2 files changed

lines changed

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.

Original file line numberDiff line numberDiff line change

@@ -2279,6 +2279,9 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)

22792279

else if ((ms.key_richcompare = key_type->tp_richcompare) != NULL) {

22802280

ms.key_compare = unsafe_object_compare;

22812281

}

2282+

else {

2283+

ms.key_compare = safe_object_compare;

2284+

}

22822285

}

22832286

else {

22842287

ms.key_compare = safe_object_compare;