Skip to content

Commit

Permalink
Backport of 8014: Don't segfault if fromfile 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 9a06197 commit a50b6a3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions numpy/core/src/multiarray/ctors.c
Expand Up @@ -968,7 +968,7 @@ setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, intp offset)
}
offset += a->strides[dim];
}

Py_DECREF(s);
return 0;

Expand Down Expand Up @@ -2774,7 +2774,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 @@ -3030,6 +3030,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 a50b6a3

Please sign in to comment.