8000 BUG: initialize op_axes when only itershape is given · numpy/numpy@e12dc1c · GitHub
[go: up one dir, main page]

Skip to content

Commit e12dc1c

Browse files
committed
BUG: initialize op_axes when only itershape is given
In this case, the initialization used the number of dimensions instead of setting it to NULL for each operand, leading to possible segmentation faults.
1 parent d111fbd commit e12dc1c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

numpy/core/src/multiarray/nditer_pywrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ npyiter_init(NewNpyArrayIterObject *self, PyObject *args, PyObject *kwds)
786786
if (itershape.len > 0) {
787787
if (oa_ndim == 0) {
788788
oa_ndim = itershape.len;
789-
memset(op_axes, 0, sizeof(op_axes[0])*oa_ndim);
789+
memset(op_axes, 0, sizeof(op_axes[0]) * nop);
790790
}
791791
else if (oa_ndim != itershape.len) {
792792
PyErr_SetString(PyExc_ValueError,

numpy/core/tests/test_nditer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ def test_iter_itershape():
598598
[['readonly'], ['writeonly','allocate']],
599599
op_axes=[[0,1,None], None],
600600
itershape=(-1,1,4))
601+
# Test bug that for no op_axes but itershape, they are NULLed correctly
602+
i = np.nditer([np.ones(2), None, None], itershape=(2,))
601603

602604
def test_iter_broadcasting_errors():
603605
# Check that errors are thrown for bad broadcasting shapes

0 commit comments

Comments
 (0)
0