From fb61bf2421093cc034c7d0985c77648188a8b209 Mon Sep 17 00:00:00 2001 From: Travis Oliphant Date: Tue, 26 Feb 2008 21:17:13 +0000 Subject: Make sure that mp is an array before testing for 0-d ness. --- numpy/core/src/arrayobject.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'numpy/core/src/arrayobject.c') diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 75c1b6e29..5b657ce63 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -3032,6 +3032,11 @@ array_subscript_nice(PyArrayObject *self, PyObject *op) mp = (PyArrayObject *)array_subscript(self, op); + /* mp could be a scalar if op is not an Int, Scalar, Long or other Index + object and still convertable to an integer (so that the code goes to + array_subscript_simple). So, this cast is a bit dangerous.. + */ + /* The following is just a copy of PyArray_Return with an additional logic in the nd == 0 case. */ @@ -3043,14 +3048,15 @@ array_subscript_nice(PyArrayObject *self, PyObject *op) return NULL; } - if (mp->nd == 0) { + if (PyArray_Check(mp) && mp->nd == 0) { Bool noellipses = TRUE; if ((op == Py_Ellipsis) || PyString_Check(op) || PyUnicode_Check(op)) noellipses = FALSE; else if (PyBool_Check(op) || PyArray_IsScalar(op, Bool) || (PyArray_Check(op) && (PyArray_DIMS(op)==0) && - PyArray_ISBOOL(op))) - noellipses = FALSE; + PyArray_ISBOOL(op))) { + noellipses = FALSE; + } else if (PySequence_Check(op)) { int n, i; PyObject *temp; -- cgit v1.2.1