diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index ae98ef7..6605540 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -800,22 +800,22 @@ readinst(char *buf, int buf_size, PyObject *meth) PyObject *arg = NULL; PyObject *bytes = NULL; PyObject *str = NULL; - Py_ssize_t len = -1; + Py_ssize_t len; char *ptr; if ((bytes = PyLong_FromLong(buf_size)) == NULL) - goto finally; + goto error; if ((arg = PyTuple_New(1)) == NULL) { Py_DECREF(bytes); - goto finally; + goto error; } PyTuple_SET_ITEM(arg, 0, bytes); str = PyObject_Call(meth, arg, NULL); if (str == NULL) - goto finally; + goto error; if (PyBytes_Check(str)) ptr = PyBytes_AS_STRING(str); @@ -825,7 +825,7 @@ readinst(char *buf, int buf_size, PyObject *meth) PyErr_Format(PyExc_TypeError, "read() did not return a bytes object (type=%.400s)", Py_TYPE(str)->tp_name); - goto finally; + goto error; } len = Py_SIZE(str); if (len > buf_size) { @@ -833,13 +833,16 @@ readinst(char *buf, int buf_size, PyObject *meth) "read() returned too much data: " "%i bytes requested, %zd returned", buf_size, len); - goto finally; + goto error; } memcpy(buf, ptr, len); + goto finally; +error: + len = -1; finally: Py_XDECREF(arg); Py_XDECREF(str); - /* len <= buf_size <= INT_MAX (see above) */ + /* len=-1 or len <= buf_size <= INT_MAX */ return (int)len; }