diff options
author | Michael Hudson-Doyle <michael.hudson@canonical.com> | 2019-10-24 21:46:00 +1300 |
---|---|---|
committer | Michael Hudson-Doyle <michael.hudson@canonical.com> | 2019-10-24 22:39:12 +1300 |
commit | af36784b2b38577a87208003d6827d02dc0c0fc2 (patch) | |
tree | f2caba8ebe4eafb608db59d6ab43146f49edcea0 /numpy/core | |
parent | c10d66ab8e153d944dc705434c5733d0e8249926 (diff) | |
download | numpy-af36784b2b38577a87208003d6827d02dc0c0fc2.tar.gz |
BUG: fix integer size confusion in handling array's ndmin argument
The ndmin local variable was changed from an "int" to an "npy_intp" but
&ndmin is passed to PyArg_ParseTupleAndKeywords against a "i" argument
spec, but these integers have different sizes (well on an LP64 platform
anyway). This actually works on a little endian system but fails
on a big endian one. Fix this by converting the local back to an int,
and being a little careful before assigning the result of PyLong_AsLong to
it.
Fixes #14767
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 441567049..9693275e7 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -1562,8 +1562,7 @@ _array_fromobject(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kws) PyArrayObject *oparr = NULL, *ret = NULL; npy_bool subok = NPY_FALSE; npy_bool copy = NPY_TRUE; - int nd; - npy_intp ndmin = 0; + int ndmin = 0, nd; PyArray_Descr *type = NULL; PyArray_Descr *oldtype = NULL; NPY_ORDER order = NPY_KEEPORDER; @@ -1625,13 +1624,14 @@ _array_fromobject(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kws) ndmin_obj = PyDict_GetItem(kws, npy_ma_str_ndmin); if (ndmin_obj) { - ndmin = PyLong_AsLong(ndmin_obj); - if (error_converting(ndmin)) { + long t = PyLong_AsLong(ndmin_obj); + if (error_converting(t)) { goto clean_type; } - else if (ndmin > NPY_MAXDIMS) { + else if (t > NPY_MAXDIMS) { goto full_path; } + ndmin = t; } /* copy=False with default dtype, order (any is OK) and ndim */ |