From 8ea9f4d10aa81251aa857362e9e3fb17511d99db Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 29 Jun 1998 22:26:50 +0000 Subject: Fix a stupid little bug: len() of an unsized returns -1 and leaves an exception waiting to happen next... --- Python/bltinmodule.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Python/bltinmodule.c') 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[] = -- cgit v1.2.1