Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Further small return value validation fixes #20992

Merged
merged 1 commit into from Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/buffer.c
Expand Up @@ -1057,7 +1057,7 @@ _descriptor_from_pep3118_format_fast(char const *s, PyObject **result)
else {
*result = (PyObject*)PyArray_DescrNewByteorder(descr, byte_order);
Py_DECREF(descr);
if (result == NULL) {
if (*result == NULL) {
return 0;
}
}
Expand Down
3 changes: 3 additions & 0 deletions numpy/core/src/multiarray/ctors.c
Expand Up @@ -1881,6 +1881,9 @@ PyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,
if (!descr && PyArray_Check(op) &&
PyArray_ISBYTESWAPPED((PyArrayObject* )op)) {
descr = PyArray_DescrNew(PyArray_DESCR((PyArrayObject *)op));
if (descr == NULL) {
return NULL;
}
}
else if (descr && !PyArray_ISNBO(descr->byteorder)) {
PyArray_DESCR_REPLACE(descr);
Expand Down
7 changes: 4 additions & 3 deletions numpy/core/src/multiarray/descriptor.c
Expand Up @@ -597,9 +597,7 @@ _convert_from_array_descr(PyObject *obj, int align)

PyArray_Descr *new = PyArray_DescrNewFromType(NPY_VOID);
if (new == NULL) {
Py_XDECREF(fields);
Py_XDECREF(nameslist);
return NULL;
goto fail;
}
new->fields = fields;
new->names = nameslist;
Expand Down Expand Up @@ -703,6 +701,9 @@ _convert_from_list(PyObject *obj, int align)
totalsize += conv->elsize;
}
PyArray_Descr *new = PyArray_DescrNewFromType(NPY_VOID);
if (new == NULL) {
goto fail;
}
new->fields = fields;
new->names = nameslist;
new->flags = dtypeflags;
Expand Down
4 changes: 4 additions & 0 deletions numpy/core/src/multiarray/methods.c
Expand Up @@ -1396,6 +1396,10 @@ array_partition(PyArrayObject *self,
return NULL;
}
newd = PyArray_DescrNew(saved);
if (newd == NULL) {
Py_DECREF(new_name);
return NULL;
}
Py_DECREF(newd->names);
newd->names = new_name;
((PyArrayObject_fields *)self)->descr = newd;
Expand Down
4 changes: 2 additions & 2 deletions tools/swig/pyfragments.swg
Expand Up @@ -52,7 +52,7 @@
}
%#endif
if (!PyArray_IsScalar(obj,Integer)) return SWIG_TypeError;
PyArray_Descr * longDescr = PyArray_DescrNewFromType(NPY_LONG);
PyArray_Descr * longDescr = PyArray_DescrFromType(NPY_LONG);
PyArray_CastScalarToCtype(obj, (void*)val, longDescr);
Py_DECREF(longDescr);
return SWIG_OK;
Expand Down Expand Up @@ -102,7 +102,7 @@
}
%#endif
if (!PyArray_IsScalar(obj,Integer)) return SWIG_TypeError;
PyArray_Descr * ulongDescr = PyArray_DescrNewFromType(NPY_ULONG);
PyArray_Descr * ulongDescr = PyArray_DescrFromType(NPY_ULONG);
PyArray_CastScalarToCtype(obj, (void*)val, ulongDescr);
Py_DECREF(ulongDescr);
return SWIG_OK;
Expand Down