summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseberg <sebastian@sipsolutions.net>2013-05-09 03:13:13 -0700
committerseberg <sebastian@sipsolutions.net>2013-05-09 03:13:13 -0700
commitb76df8583ef966d434c9b87fd22422c68e6bd44e (patch)
tree943fc415bbe52a18e3fe20ad5af5ddb6c7bd7860
parent0af5f87b0b5c25ce0d71dca8686414fa47708106 (diff)
parent09b25ceb655552910e549c2fd73ccce05271f588 (diff)
downloadnumpy-b76df8583ef966d434c9b87fd22422c68e6bd44e.tar.gz
Merge pull request #3313 from ecatmur/master
BUG: fix potentially infinite recursion in VOID_nonzero. Fixes #3312.
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src2
-rw-r--r--numpy/core/tests/test_regression.py5
2 files changed, 6 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index aff4c36dd..4a5c13a6a 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -2321,7 +2321,7 @@ VOID_nonzero (char *ip, PyArrayObject *ap)
* TODO: temporarily modifying the array like this
* is bad coding style, should be changed.
*/
- ((PyArrayObject_fields *)ap)->descr = descr;
+ ((PyArrayObject_fields *)ap)->descr = new;
((PyArrayObject_fields *)ap)->flags = savedflags;
if ((new->alignment > 1) && !__ALIGNED(ip + offset,
new->alignment)) {
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index cb8415ee7..bb0bf029b 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1898,6 +1898,11 @@ class TestRegression(TestCase):
order='F')
assert_array_equal(arr2, data_back)
+ def test_structured_count_nonzero(self):
+ arr = np.array([0, 1]).astype('i4, (2)i4')[:1]
+ count = np.count_nonzero(arr)
+ assert_equal(count, 0)
+