]> granicus.if.org Git - python/commitdiff
SF bug #1030557: PyMapping_Check crashes when argument is NULL
authorRaymond Hettinger <python@rcn.com>
Sun, 19 Sep 2004 06:00:15 +0000 (06:00 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 19 Sep 2004 06:00:15 +0000 (06:00 +0000)
Make PySequence_Check() and PyMapping_Check() handle NULL inputs.  This
goes beyond what most of the other checks do, but it is nice defensive
programming and solves the OP's problem.

Objects/abstract.c

index bc36c6fdd4311ee3975f721162d8e01561269a44..377f359300d3e719a2f95d0032d935326b22e3b6 100644 (file)
@@ -1085,7 +1085,7 @@ PyNumber_Float(PyObject *o)
 int
 PySequence_Check(PyObject *s)
 {
-       if (PyInstance_Check(s))
+       if (s && PyInstance_Check(s))
                return PyObject_HasAttrString(s, "__getitem__");
        return s != NULL && s->ob_type->tp_as_sequence &&
                s->ob_type->tp_as_sequence->sq_item != NULL;
@@ -1629,7 +1629,7 @@ PySequence_Index(PyObject *s, PyObject *o)
 int
 PyMapping_Check(PyObject *o)
 {
-       if (PyInstance_Check(o))
+       if (o && PyInstance_Check(o))
                return PyObject_HasAttrString(o, "__getitem__");
 
        return  o && o->ob_type->tp_as_mapping &&