diff options
author | Mike Kelly <mtk@numeric.com> | 2014-05-16 13:09:29 -0400 |
---|---|---|
committer | Mike Kelly <mtk@numeric.com> | 2014-05-16 16:01:29 -0400 |
commit | 9ca38a508cd9836d1b1bcf5c3dedd1fe8b6cb14c (patch) | |
tree | 16914e240902d4eac3357606f014d89d40717a6a | |
parent | ee494114ee1f439b1183ef7030ade599f96be7e1 (diff) | |
download | numpy-9ca38a508cd9836d1b1bcf5c3dedd1fe8b6cb14c.tar.gz |
BUG: Fix seg fault converting empty string to object
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_dtype.py | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index 8e22afa31..ffd741dea 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -426,7 +426,7 @@ STRING_getitem(char *ip, PyArrayObject *ap) int size = PyArray_DESCR(ap)->elsize; ptr = ip + size - 1; - while (*ptr-- == '\0' && size > 0) { + while (size > 0 && *ptr-- == '\0') { size--; } return PyBytes_FromStringAndSize(ip,size); diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index 2e98b2cf8..18660351c 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -496,6 +496,10 @@ class TestString(TestCase): # Issue gh-2798 a = np.array(['a'], dtype="O").astype(("O", [("name", "O")])) + def test_empty_string_to_object(self): + # Pull request #4722 + np.array(["", ""]).astype(object) + class TestDtypeAttributeDeletion(object): def test_dtype_non_writable_attributes_deletion(self): |