Skip to content

Commit 3338038

Browse files
ngoldbaumcharris
authored andcommitted
BUG: PyObject_IsTrue and PyObject_Not error handling in setflags
1 parent ef46300 commit 3338038

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

numpy/core/src/multiarray/methods.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,7 +2713,11 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)
27132713
return NULL;
27142714

27152715
if (align_flag != Py_None) {
2716-
if (PyObject_Not(align_flag)) {
2716+
int isnot = PyObject_Not(align_flag);
2717+
if (isnot == -1) {
2718+
return NULL;
2719+
}
2720+
if (isnot) {
27172721
PyArray_CLEARFLAGS(self, NPY_ARRAY_ALIGNED);
27182722
}
27192723
else if (IsAligned(self)) {
@@ -2728,7 +2732,11 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)
27282732
}
27292733

27302734
if (uic != Py_None) {
2731-
if (PyObject_IsTrue(uic)) {
2735+
int istrue = PyObject_IsTrue(uic);
2736+
if (istrue == -1) {
2737+
return NULL;
2738+
}
2739+
if (istrue) {
27322740
fa->flags = flagback;
27332741
PyErr_SetString(PyExc_ValueError,
27342742
"cannot set WRITEBACKIFCOPY "
@@ -2743,7 +2751,11 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)
27432751
}
27442752

27452753
if (write_flag != Py_None) {
2746-
if (PyObject_IsTrue(write_flag)) {
2754+
int istrue = PyObject_IsTrue(write_flag);
2755+
if (istrue == -1) {
2756+
return NULL;
2757+
}
2758+
else if (istrue == 1) {
27472759
if (_IsWriteable(self)) {
27482760
/*
27492761
* _IsWritable (and PyArray_UpdateFlags) allows flipping this,

0 commit comments

Comments
 (0)