]> granicus.if.org Git - python/commitdiff
Fix a stupid little bug: len() of an unsized returns -1 and leaves an
authorGuido van Rossum <guido@python.org>
Mon, 29 Jun 1998 22:26:50 +0000 (22:26 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 29 Jun 1998 22:26:50 +0000 (22:26 +0000)
exception waiting to happen next...

Python/bltinmodule.c

index 727f8d19946eefdb7cdd72e9eb59317e3d7ad080..775c318becae69217d677efc68a9c5e1297ded33 100644 (file)
@@ -1098,10 +1098,14 @@ builtin_len(self, args)
        PyObject *args;
 {
        PyObject *v;
+       long res;
 
        if (!PyArg_ParseTuple(args, "O:len", &v))
                return NULL;
-       return PyInt_FromLong((long)PyObject_Length(v));
+       res = PyObject_Length(v);
+       if (res < 0 && PyErr_Occurred())
+               return NULL;
+       return PyInt_FromLong(res);
 }
 
 static char len_doc[] =