Skip to content

Commit

Permalink
Don't segfault if file reading is somehow faulty
Browse files Browse the repository at this point in the history
  • Loading branch information
mdroe committed Dec 15, 2009
1 parent effa092 commit 6938cc0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion numpy/core/src/multiarray/ctors.c
Original file line number Diff line number Diff line change
Expand Up @@ -2786,7 +2786,7 @@ PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr
/* calculate the length and next = start + step*/
length = _calc_length(start, stop, step, &next,
PyTypeNum_ISCOMPLEX(dtype->type_num));
err = PyErr_Occurred();
err = PyErr_Occurred();
if (err) {
Py_DECREF(dtype);
if (err && PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) {
Expand Down Expand Up @@ -3042,6 +3042,10 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, intp num, char *sep)
(next_element) fromfile_next_element,
(skip_separator) fromfile_skip_separator, NULL);
}
if (ret == NULL) {
Py_DECREF(dtype);
return NULL;
}
if (((intp) nread) < num) {
/* Realloc memory for smaller number of elements */
const size_t nsize = NPY_MAX(nread,1)*ret->descr->elsize;
Expand Down

0 comments on commit 6938cc0

Please sign in to comment.