diff options
author | Han Genuit <hangenuit@gmail.com> | 2012-09-14 11:11:29 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2013-04-11 16:59:40 +0200 |
commit | d128fcb4c292a27fb22befe3b2016808d79054b0 (patch) | |
tree | 27ff3d38bb1c89bdc63291cddac637d7837602e0 | |
parent | e7db8c0f5ef7a302e05be767ebe9cfa81d953a6d (diff) | |
download | numpy-d128fcb4c292a27fb22befe3b2016808d79054b0.tar.gz |
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.
-rw-r--r-- | numpy/core/src/multiarray/mapping.c | 9 |
1 files changed, 9 insertions, 0 deletions
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 */ |