mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
In PyObject_IsTrue(), don't call function pointers that are NULL
(nb_nonzero, mp_length, sq_length).
This commit is contained in:
parent
7e33c6e896
commit
1c4f458099
1 changed files with 6 additions and 3 deletions
|
@ -469,11 +469,14 @@ PyObject_IsTrue(v)
|
||||||
int res;
|
int res;
|
||||||
if (v == Py_None)
|
if (v == Py_None)
|
||||||
res = 0;
|
res = 0;
|
||||||
else if (v->ob_type->tp_as_number != NULL)
|
else if (v->ob_type->tp_as_number != NULL &&
|
||||||
|
v->ob_type->tp_as_number->nb_nonzero != NULL)
|
||||||
res = (*v->ob_type->tp_as_number->nb_nonzero)(v);
|
res = (*v->ob_type->tp_as_number->nb_nonzero)(v);
|
||||||
else if (v->ob_type->tp_as_mapping != NULL)
|
else if (v->ob_type->tp_as_mapping != NULL &&
|
||||||
|
v->ob_type->tp_as_mapping->mp_length != NULL)
|
||||||
res = (*v->ob_type->tp_as_mapping->mp_length)(v);
|
res = (*v->ob_type->tp_as_mapping->mp_length)(v);
|
||||||
else if (v->ob_type->tp_as_sequence != NULL)
|
else if (v->ob_type->tp_as_sequence != NULL &&
|
||||||
|
v->ob_type->tp_as_sequence->sq_length != NULL)
|
||||||
res = (*v->ob_type->tp_as_sequence->sq_length)(v);
|
res = (*v->ob_type->tp_as_sequence->sq_length)(v);
|
||||||
else
|
else
|
||||||
res = 1;
|
res = 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue