From d128fcb4c292a27fb22befe3b2016808d79054b0 Mon Sep 17 00:00:00 2001 From: Han Genuit Date: Fri, 14 Sep 2012 11:11:29 +0200 Subject: ENH: Add exception to _nonzero_indices for zero-dim arrays This function causes a crash otherwise, because it loops over the number of dimensions to construct sub-iterators. If the number of dimensions is zero, the sub-iterators will not be initialized, causing problems later on. --- numpy/core/src/multiarray/mapping.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c index 990f95d3b..254fa9117 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -1576,6 +1576,14 @@ _nonzero_indices(PyObject *myBool, PyArrayIterObject **iters) return -1; } nd = PyArray_NDIM(ba); + + if (nd == 0) { + PyErr_SetString(PyExc_ValueError, + "cannot construct index objects " + "for zero-dimensional array"); + goto fail; + } + for (j = 0; j < nd; j++) { iters[j] = NULL; } @@ -1614,6 +1622,7 @@ _nonzero_indices(PyObject *myBool, PyArrayIterObject **iters) } /* + * Loop through the Boolean array and copy coordinates * for non-zero entries */ -- cgit v1.2.1