diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-01-08 07:15:18 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-01-08 07:15:18 +0000 |
commit | a71140e506732899d279269bd3ac98be9e823cec (patch) | |
tree | 18d102c6c945529cf634601953f4696f87602728 /numpy/core/src | |
parent | 4596572c65c77590fff709a85a3992254cc145d3 (diff) | |
download | numpy-a71140e506732899d279269bd3ac98be9e823cec.tar.gz |
Fixed up so that at least element-size is allocated and iterator of size-0 raises an error
Diffstat (limited to 'numpy/core/src')
-rw-r--r-- | numpy/core/src/arrayobject.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index ec6d93892..32fd6eb4a 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -3538,7 +3538,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, e.g. shape=(0,) -- otherwise buffer exposure (a.data) doesn't work as it should. */ - if (sd==0) sd = sizeof(intp); + if (sd==0) sd = descr->elsize; if ((data = PyDataMem_NEW(sd))==NULL) { PyErr_NoMemory(); @@ -3642,8 +3642,8 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape) return NULL; } - sd = (newsize == 0 ? sizeof(intp) : \ - newsize * self->descr->elsize); + if (newsize == 0) sd = self->descr->elsize; + else sd = newsize * self->descr->elsize; /* Reallocate space if needed */ new_data = PyDataMem_RENEW(self->data, sd); if (new_data == NULL) { @@ -6215,6 +6215,11 @@ PyArray_IterNew(PyObject *obj) Py_INCREF(ao); it->ao = ao; it->size = PyArray_SIZE(ao); + if (it->size == 0) { + PyErr_SetString(PyExc_ValueError, + "Cannot iterate over a size-0 array"); + return NULL; + } it->nd_m1 = nd - 1; it->factors[nd-1] = 1; for (i=0; i < nd; i++) { |