Permalink
Browse files

BUG: Disallow shapesize > 1 when coercing scalar to array

  • Loading branch information...
1 parent 097e823 commit de3075f5484a6e71273633bc1202c0971f8889e2 @87 committed Sep 30, 2012
Showing with 7 additions and 0 deletions.
  1. +7 −0 numpy/core/src/multiarray/ctors.c
@@ -2150,6 +2150,7 @@ PyArray_FromInterface(PyObject *origin)
data += num;
}
}
+
ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
n, dims,
NULL, data,
@@ -2158,6 +2159,12 @@ PyArray_FromInterface(PyObject *origin)
goto fail;
}
if (data == NULL) {
+ if (PyArray_SIZE(ret) > 1) {
+ PyErr_SetString(PyExc_ValueError,
+ "cannot coerce scalar to array with size > 1");
+ Py_DECREF(ret);
+ goto fail;
+ }
if (PyArray_SETITEM(ret, PyArray_DATA(ret), origin) < 0) {
Py_DECREF(ret);
goto fail;

0 comments on commit de3075f

Please sign in to comment.