Skip to content

Commit 9656aaf

Browse files
committed
BUG: add missing checks for nullptr in rankdata and nanrankdata
1 parent 55ac4aa commit 9656aaf

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

bottleneck/src/nonreduce_axis_template.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,13 @@ NRA(rankdata, DTYPE0) {
202202
npy_DTYPE1 old, new, averank, sumranks = 0;
203203

204204
PyObject *z = PyArray_ArgSort(a, axis, NPY_QUICKSORT);
205+
if (z == NULL) return NULL;
205206
PyObject *y = PyArray_EMPTY(PyArray_NDIM(a),
206207
PyArray_SHAPE(a), NPY_DTYPE1, 0);
207-
208+
if (y == NULL) {
209+
Py_DECREF(z);
210+
return NULL;
211+
}
208212
iter3 it;
209213
init_iter3(&it, a, y, z, axis);
210214

@@ -264,8 +268,13 @@ NRA(nanrankdata, DTYPE0) {
264268
npy_DTYPE1 old, new, averank, sumranks = 0;
265269

266270
PyObject *z = PyArray_ArgSort(a, axis, NPY_QUICKSORT);
271+
if (z == NULL) return NULL;
267272
PyObject *y = PyArray_EMPTY(PyArray_NDIM(a),
268273
PyArray_SHAPE(a), NPY_DTYPE1, 0);
274+
if (y == NULL) {
275+
Py_DECREF(z);
276+
return NULL;
277+
}
269278

270279
iter3 it;
271280
init_iter3(&it, a, y, z, axis);

0 commit comments

Comments
 (0)