Skip to content

Commit

Permalink
MAINT: Add a check of the return value of PyMem_Calloc().
Browse files Browse the repository at this point in the history
  • Loading branch information
WarrenWeckesser committed Jun 16, 2022
1 parent 2d44524 commit 570e59e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions numpy/core/src/multiarray/textreading/readtext.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ _load_from_filelike(PyObject *NPY_UNUSED(mod),
}
/* Calloc just to not worry about overflow */
usecols = PyMem_Calloc(num_usecols, sizeof(Py_ssize_t));
if (usecols == NULL) {
PyErr_NoMemory();
return NULL;
}
for (Py_ssize_t i = 0; i < num_usecols; i++) {
PyObject *tmp = PySequence_GetItem(usecols_obj, i);
if (tmp == NULL) {
Expand Down

0 comments on commit 570e59e

Please sign in to comment.