[New-bugs-announce] [issue33989] ms.key_compare is not initialized in all pathes of list_sort_impl
Pochang Chen
report at bugs.python.org
Thu Jun 28 13:43:06 EDT 2018
New submission from Pochang Chen <johnchen902 at gmail.com>:
Relevant code (Objects/listobject.c lines 2268 -- 2286 as of commit e76ac9d):
/* Choose the best compare, given what we now know about the keys. */
if (keys_are_all_same_type) {
if (key_type == &PyUnicode_Type && strings_are_latin) {
ms.key_compare = unsafe_latin_compare;
}
else if (key_type == &PyLong_Type && ints_are_bounded) {
ms.key_compare = unsafe_long_compare;
}
else if (key_type == &PyFloat_Type) {
ms.key_compare = unsafe_float_compare;
}
else if ((ms.key_richcompare = key_type->tp_richcompare) != NULL) {
ms.key_compare = unsafe_object_compare;
}
}
else {
ms.key_compare = safe_object_compare;
}
Clearly, ms.key_compare is not assigned here if keys_are_all_same_type is true but key_type->tp_richcompare is NULL.
I don't know how to obtain an object with ob_type->tp_richcompare being NULL, though.
----------
components: Interpreter Core
messages: 320679
nosy: johnchen902
priority: normal
severity: normal
status: open
title: ms.key_compare is not initialized in all pathes of list_sort_impl
type: crash
versions: Python 3.7, Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33989>
_______________________________________
More information about the New-bugs-announce
mailing list