summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarraymodule.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c
index 94922a3bf..f6e9ddd32 100644
--- a/numpy/core/src/multiarraymodule.c
+++ b/numpy/core/src/multiarraymodule.c
@@ -3679,7 +3679,7 @@ PyArray_ArgMax(PyArrayObject *op, int axis, PyArrayObject *out)
*/
ap = (PyArrayObject *)\
PyArray_ContiguousFromAny((PyObject *)op,
- op->descr->type_num, 1, 0);
+ op->descr->type_num, 1, 0);
Py_DECREF(op);
if (ap == NULL) return NULL;
@@ -5998,8 +5998,8 @@ array_from_text(PyArray_Descr *dtype, intp num, char *sep, size_t *nread,
{
PyArrayObject *r;
intp i;
- char *dptr, *clean_sep;
-
+ char *dptr, *clean_sep, *tmp;
+ int err = 0;
intp thisbuf = 0;
intp size;
intp bytes, totalbytes;
@@ -6025,19 +6025,29 @@ array_from_text(PyArray_Descr *dtype, intp num, char *sep, size_t *nread,
dptr += dtype->elsize;
if (num < 0 && thisbuf == size) {
totalbytes += bytes;
- r->data = PyDataMem_RENEW(r->data, totalbytes);
- dptr = r->data + (totalbytes - bytes);
+ tmp = PyDataMem_RENEW(r->data, totalbytes);
+ if (tmp == NULL) {
+ err = 1;
+ break;
+ }
+ r->data = tmp;
+ dptr = tmp + (totalbytes - bytes);
thisbuf = 0;
}
if (skip_sep(&stream, clean_sep, stream_data) < 0)
break;
}
if (num < 0) {
- r->data = PyDataMem_RENEW(r->data, (*nread)*dtype->elsize);
- PyArray_DIM(r,0) = *nread;
+ tmp = PyDataMem_RENEW(r->data, (*nread)*dtype->elsize);
+ if (tmp == NULL) err=1;
+ else {
+ PyArray_DIM(r,0) = *nread;
+ r->data = tmp;
+ }
}
NPY_END_ALLOW_THREADS;
free(clean_sep);
+ if (err == 1) PyErr_NoMemory();
if (PyErr_Occurred()) {
Py_DECREF(r);
return NULL;
@@ -6229,6 +6239,7 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, intp num, char *sep)
{
PyArrayObject *ret;
size_t nread = 0;
+ char *tmp;
if (PyDataType_REFCHK(dtype)) {
PyErr_SetString(PyExc_ValueError,
@@ -6262,8 +6273,13 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, intp num, char *sep)
if (((intp) nread) < num) {
fprintf(stderr, "%ld items requested but only %ld read\n",
(long) num, (long) nread);
- ret->data = PyDataMem_RENEW(ret->data,
- nread * ret->descr->elsize);
+ tmp = PyDataMem_RENEW(ret->data,
+ nread * ret->descr->elsize);
+ if (tmp == NULL) {
+ Py_DECREF(ret);
+ return PyErr_NoMemory();
+ }
+ ret->data = tmp;
PyArray_DIM(ret,0) = nread;
}
return (PyObject *)ret;
@@ -6384,11 +6400,12 @@ PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, intp count)
(assuming realloc is reasonably good about reusing space...)
*/
if (i==0) i = 1;
- ret->data = PyDataMem_RENEW(ret->data, i * elsize);
- if (ret->data == NULL) {
+ new_data = PyDataMem_RENEW(ret->data, i * elsize);
+ if (new_data == NULL) {
PyErr_SetString(PyExc_MemoryError, "cannot allocate array memory");
goto done;
}
+ ret->data = new_data;
done:
Py_XDECREF(iter);