8000 MAINT: check enum at API call, not in provate function · numpy/numpy@26079cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 26079cf

Browse files
committed
MAINT: check enum at API call, not in provate function
1 parent f41d704 commit 26079cf

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

numpy/core/src/common/npy_partition.h.src

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ get_argpartition_func(int type, NPY_SELECTKIND which)
113113
npy_intp i;
114114
npy_intp ntypes = ARRAY_SIZE(_part_map);
115115

116-
if (which >= NPY_NSELECTS) {
117-
return NULL;
118-
}
119116
for (i = 0; i < ntypes; i++) {
120117
if (type == _part_map[i].typenum) {
121118
return _part_map[i].argpart[which];

numpy/core/src/multiarray/item_selection.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,11 @@ PyArray_ArgPartition(PyArrayObject *op, PyArrayObject *ktharray, int axis,
13361336
PyArray_ArgSortFunc *argsort;
13371337
PyObject *ret;
13381338

1339-
if (which < 0 || which >= NPY_NSELECTS) {
1339+
/*
1340+
* As a C-exported function, enum NPY_SELECTKIND loses its enum property
1341+
* Check the values to make sure they are in range
1342+
*/
1343+
if ((int)which < 0 || (int)which >= NPY_NSELECTS) {
13401344
PyErr_SetString(PyExc_ValueError,
13411345
"not a valid partition kind");
13421346
return NULL;

0 commit comments

Comments
 (0)
0