diff options
| author | Mike Kelly <mtk@numeric.com> | 2014-05-16 13:09:29 -0400 |
|---|---|---|
| committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-08-08 23:54:12 +0200 |
| commit | a785c79206528385d76bc6366774cb6d9cacbcda (patch) | |
| tree | ddd1cf75526a5bde992252e6ba12eed766a699d4 /numpy/core | |
| parent | c7ad14f5f3069e93a674e0ddf260d7da6c71a5a7 (diff) | |
| download | numpy-a785c79206528385d76bc6366774cb6d9cacbcda.tar.gz | |
BUG: Fix seg fault converting empty string to object
Diffstat (limited to 'numpy/core')
| -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 03a9df28f..7527f501e 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -394,7 +394,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 83017ea6a..a5777b2fb 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -449,6 +449,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): |
