]> granicus.if.org Git - python/commitdiff
In PyObject_IsTrue(), don't call function pointers that are NULL
authorGuido van Rossum <guido@python.org>
Fri, 22 May 1998 00:53:24 +0000 (00:53 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 22 May 1998 00:53:24 +0000 (00:53 +0000)
(nb_nonzero, mp_length, sq_length).

Objects/object.c

index 0588fea5061da0608166ff9daa98fb69125a8efb..964c5c59f29e97375dbe05f7bcf15200003d279b 100644 (file)
@@ -469,11 +469,14 @@ PyObject_IsTrue(v)
        int res;
        if (v == Py_None)
                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);
-       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);
-       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);
        else
                res = 1;