summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2017-06-27 10:47:33 +0200
committerJulian Taylor <jtaylor.debian@googlemail.com>2017-06-27 10:57:04 +0200
commit1b209d0c7d7d9e054f0b06a44595af1455db0c6a (patch)
tree2aee57779a54537d2df3ef63aaf23fd304863709 /numpy
parent7bd7283ce3325ccae4ae2f5628166b605af773cb (diff)
downloadnumpy-1b209d0c7d7d9e054f0b06a44595af1455db0c6a.tar.gz
BUG: fix wrong ndim used in empty where check
closes gh-9304
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/item_selection.c2
-rw-r--r--numpy/core/tests/test_multiarray.py11
2 files changed, 12 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c
index c88cdfdcb..e60145508 100644
--- a/numpy/core/src/multiarray/item_selection.c
+++ b/numpy/core/src/multiarray/item_selection.c
@@ -2330,7 +2330,7 @@ finish:
return NULL;
}
- for (i = 0; i < ndim; ++i) {
+ for (i = 0; i < PyArray_NDIM(ret); ++i) {
if (PyArray_DIMS(ret)[i] == 0) {
is_empty = 1;
break;
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 3c07902a7..f2968eb3e 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -6620,6 +6620,17 @@ class TestWhere(TestCase):
assert_array_equal(ibad,
np.atleast_2d(np.array([[],[]], dtype=np.intp)))
+ def test_largedim(self):
+ # invalid read regression gh-9304
+ shape = [10, 2, 3, 4, 5, 6]
+ np.random.seed(2)
+ array = np.random.rand(*shape)
+
+ for i in range(10):
+ benchmark = array.nonzero()
+ result = array.nonzero()
+ assert_array_equal(benchmark, result)
+
if not IS_PYPY:
# sys.getsizeof() is not valid on PyPy