From: Guido van Rossum Date: Mon, 29 Jun 1998 22:26:50 +0000 (+0000) Subject: Fix a stupid little bug: len() of an unsized returns -1 and leaves an X-Git-Tag: v1.5.2a1~384 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ea9f4d10aa81251aa857362e9e3fb17511d99db;p=python Fix a stupid little bug: len() of an unsized returns -1 and leaves an exception waiting to happen next... --- diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 727f8d1994..775c318bec 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -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[] =