diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/ctors.c | 6 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 3 |
2 files changed, 5 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index 261e6754b..a026ecb4d 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -978,14 +978,14 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, return NULL; } - size *= dim; - - if (size > largest) { + if (dim > largest) { PyErr_SetString(PyExc_ValueError, "array is too big."); Py_DECREF(descr); return NULL; } + size *= dim; + largest /= dim; } self = (PyArrayObject *) subtype->tp_alloc(subtype, 0); diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index cb65c8cef..281342bbf 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -1152,7 +1152,8 @@ class TestRegression(TestCase): def test_array_too_big(self): """Ticket #1080.""" - assert_raises(ValueError, np.zeros, [2**10]*10) + assert_raises(ValueError, np.zeros, [2**10]*10, np.int8) + assert_raises(MemoryError, np.zeros, [2**30]*2, np.int8) def test_dtype_keyerrors_(self): """Ticket #1106.""" |