diff options
author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2009-03-06 03:04:07 (GMT) |
---|---|---|
committer | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2009-03-06 03:04:07 (GMT) |
commit | 54d0df69c0a57b5d5447f483494293354656c4fa (patch) | |
tree | 37c4c0e898a6fefb53359f83d5d6b23e23d1e992 /Modules | |
parent | 3aed8d511014df6409758706e5179aeeb7cc80ee (diff) | |
download | cpython-54d0df69c0a57b5d5447f483494293354656c4fa.zip cpython-54d0df69c0a57b5d5447f483494293354656c4fa.tar.gz cpython-54d0df69c0a57b5d5447f483494293354656c4fa.tar.bz2 |
Issue #5334: array.fromfile() failed to insert values when EOFError was raised.
Reviewed by Benjamin Peterson.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/arraymodule.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index e55c2d0..b39da8e 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1201,6 +1201,7 @@ array_fromfile(arrayobject *self, PyObject *args) PyObject *f, *b, *res; Py_ssize_t itemsize = self->ob_descr->itemsize; Py_ssize_t n, nbytes; + int not_enough_bytes; if (!PyArg_ParseTuple(args, "On:fromfile", &f, &n)) return NULL; @@ -1222,12 +1223,7 @@ array_fromfile(arrayobject *self, PyObject *args) return NULL; } - if (PyBytes_GET_SIZE(b) != nbytes) { - PyErr_SetString(PyExc_EOFError, - "read() didn't return enough bytes"); - Py_DECREF(b); - return NULL; - } + not_enough_bytes = (PyBytes_GET_SIZE(b) != nbytes); args = Py_BuildValue("(O)", b); Py_DECREF(b); @@ -1236,6 +1232,15 @@ array_fromfile(arrayobject *self, PyObject *args) res = array_fromstring(self, args); Py_DECREF(args); + if (res == NULL) + return NULL; + + if (not_enough_bytes) { + PyErr_SetString(PyExc_EOFError, + "read() didn't return enough bytes"); + Py_DECREF(res); + return NULL; + } return res; } |