diff options
Diffstat (limited to 'numpy/core/src/multiarraymodule.c')
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index 6eb1be1fa..6aa7499bc 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -5186,11 +5186,15 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep) binary = ((sep == NULL) || (strlen(sep) == 0)); if (num == -1 && binary) { /* Get size for binary file*/ intp start, numbytes; + int fail=0; start = (intp )ftell(fp); - fseek(fp, 0, SEEK_END); - numbytes = (intp )ftell(fp) - start; - rewind(fp); - if (numbytes == -1) { + if (start < 0) fail=1; + if (fseek(fp, 0, SEEK_END) < 0) fail=1; + numbytes = (intp) ftell(fp); + if (numbytes < 0) fail=1; + numbytes -= start; + if (fseek(fp, start, SEEK_SET) < 0) fail=1; + if (fail) { PyErr_SetString(PyExc_IOError, "could not seek in file"); Py_DECREF(typecode); |