diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2014-09-19 14:33:52 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2014-09-19 14:33:52 -0600 |
commit | 882c02853f0cc3d08e46b25ff199bd10061e340f (patch) | |
tree | d208517981c09efdc1978fa4e2ad74a574a08784 | |
parent | 4083883228d61a3b571dec640185b5a5d983bf59 (diff) | |
parent | 5a14415b0aa8df194b68da840d6a58297e1e03b0 (diff) | |
download | numpy-882c02853f0cc3d08e46b25ff199bd10061e340f.tar.gz |
Merge pull request #5087 from juliantaylor/unicode-argmin
BUG: fix out of bound access in unicode argmin/argmax
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index 6550a810f..2cbb28f4b 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -3017,7 +3017,7 @@ static int memcpy(mp, ip, elsize); *max_ind = 0; for (i = 1; i < n; i++) { - ip += elsize; + ip += elsize / sizeof(@type@); if (@fname@_compare(ip, mp, aip) > 0) { memcpy(mp, ip, elsize); *max_ind = i; @@ -3074,7 +3074,7 @@ static int memcpy(mp, ip, elsize); *min_ind = 0; for(i=1; i<n; i++) { - ip += elsize; + ip += elsize / sizeof(@type@); if (@fname@_compare(mp,ip,aip) > 0) { memcpy(mp, ip, elsize); *min_ind=i; diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 27f908fe4..f7b7b5022 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -2366,6 +2366,11 @@ class TestArgmax(TestCase): a.argmax(-1, out=out) assert_equal(out, a.argmax(-1)) + def test_argmax_unicode(self): + d = np.zeros(6031, dtype='<U9') + d[5942] = "as" + assert_equal(d.argmax(), 5942) + class TestArgmin(TestCase): @@ -2471,6 +2476,11 @@ class TestArgmin(TestCase): a.argmin(-1, out=out) assert_equal(out, a.argmin(-1)) + def test_argmin_unicode(self): + d = np.ones(6031, dtype='<U9') + d[6001] = "0" + assert_equal(d.argmin(), 6001) + class TestMinMax(TestCase): def test_scalar(self): |