diff options
| author | mattip <matti.picus@gmail.com> | 2018-09-25 17:10:38 +0300 |
|---|---|---|
| committer | mattip <matti.picus@gmail.com> | 2018-09-25 17:10:38 +0300 |
| commit | e9d3e2045af728504d4a8ea16fbf2fb2d0a47bbf (patch) | |
| tree | 77351c72cd542c74bac0b6a159114a366bb8579d /numpy | |
| parent | 4ae58117a3265e3a6a61f06c51bcd19b38f8b294 (diff) | |
| download | numpy-e9d3e2045af728504d4a8ea16fbf2fb2d0a47bbf.tar.gz | |
BUG: check return value from PyArray_PromoteTypes
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/src/multiarray/convert_datatype.c | 6 | ||||
| -rw-r--r-- | numpy/core/tests/test_multiarray.py | 4 |
2 files changed, 9 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c index 3df764a48..83343b861 100644 --- a/numpy/core/src/multiarray/convert_datatype.c +++ b/numpy/core/src/multiarray/convert_datatype.c @@ -2028,7 +2028,7 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) { int i, n, allscalars = 0; PyArrayObject **mps = NULL; - PyObject *otmp; + PyObject *otmp = NULL; PyArray_Descr *intype = NULL, *stype = NULL; PyArray_Descr *newtype = NULL; NPY_SCALARKIND scalarkind = NPY_NOSCALAR, intypekind = NPY_NOSCALAR; @@ -2112,6 +2112,9 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) newtype = PyArray_PromoteTypes(intype, stype); Py_XDECREF(intype); intype = newtype; + if (newtype == NULL) { + goto fail; + } } for (i = 0; i < n; i++) { Py_XDECREF(mps[i]); @@ -2147,6 +2150,7 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) fail: Py_XDECREF(intype); Py_XDECREF(stype); + Py_XDECREF(otmp); *retn = 0; for (i = 0; i < n; i++) { Py_XDECREF(mps[i]); diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 277f64a5d..6fbdb7c6c 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -1416,6 +1416,10 @@ class TestMethods(object): A = ind.choose((x, y2)) assert_equal(A, [[2, 2, 3], [2, 2, 3]]) + oned = np.ones(1) + # gh-12031, caused SEGFAULT + assert_raises(TypeError, oned.choose,np.void(0), [oned]) + def test_prod(self): ba = [1, 2, 10, 11, 6, 5, 4] ba2 = [[1, 2, 3, 4], [5, 6, 7, 9], [10, 3, 4, 5]] |
