8000 Merge pull request #5088 from juliantaylor/not-fix · numpy/numpy@2e3778a · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2e3778a

Browse files
committed
Merge pull request #5088 from juliantaylor/not-fix
BUG: fix wrong error checks of PyBytes_AsStringAndSize
2 parents c85e31e + e50e17c commit 2e3778a

File tree

9 files changed

+14
-11
lines changed

9 files changed

+14
-11
lines changed

numpy/core/src/multiarray/arraytypes.c.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap)
503503
return -1;
504504
}
505505
#endif
506-
if (PyBytes_AsStringAndSize(temp, &ptr, &len) == -1) {
506+
if (PyBytes_AsStringAndSize(temp, &ptr, &len) < 0) {
507507
Py_DECREF(temp);
508508
return -1;
509509
}

numpy/core/src/multiarray/buffer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ _buffer_format_string(PyArray_Descr *descr, _tmp_string_t *str,
270270
tmp = name;
271271
#endif
272272
if (tmp == NULL || PyBytes_AsStringAndSize(tmp, &p, &len) < 0) {
273+
PyErr_Clear();
273274
PyErr_SetString(PyExc_ValueError, "invalid field name");
274275
return -1;
275276
}

numpy/core/src/multiarray/conversion_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ PyArray_CastingConverter(PyObject *obj, NPY_CASTING *casting 10000 )
697697
return ret;
698698
}
699699

700-
if (PyBytes_AsStringAndSize(obj, &str, &length) == -1) {
700+
if (PyBytes_AsStringAndSize(obj, &str, &length) < 0) {
701701
return 0;
702702
}
703703

numpy/core/src/multiarray/datetime.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ convert_pyobject_to_datetime(PyArray_DatetimeMetaData *meta, PyObject *obj,
23732373
bytes = obj;
23742374
Py_INCREF(bytes);
23752375
}
2376-
if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1) {
2376+
if (PyBytes_AsStringAndSize(bytes, &str, &len) < 0) {
23772377
Py_DECREF(bytes);
23782378
return -1;
23792379
}
@@ -2563,7 +2563,7 @@ convert_pyobject_to_timedelta(PyArray_DatetimeMetaData *meta, PyObject *obj,
25632563
bytes = obj;
25642564
Py_INCREF(bytes);
25652565
}
2566-
if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1) {
2566+
if (PyBytes_AsStringAndSize(bytes, &str, &len) < 0) {
25672567
Py_DECREF(bytes);
25682568
return -1;
25692569
}

numpy/core/src/multiarray/descriptor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,7 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args)
24762476
endian_obj = tmp;
24772477
}
24782478

2479-
if (PyBytes_AsStringAndSize(endian_obj, &str, &len) == -1) {
2479+
if (PyBytes_AsStringAndSize(endian_obj, &str, &len) < 0) {
24802480
Py_XDECREF(tmp);
24812481
return NULL;
24822482
}

numpy/core/src/multiarray/methods.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,7 @@ array_setstate(PyArrayObject *self, PyObject *args)
16861686
return NULL;
16871687
}
16881688

1689-
if (PyBytes_AsStringAndSize(rawdata, &datastr, &len)) {
1689+
if (PyBytes_AsStringAndSize(rawdata, &datastr, &len) < 0) {
16901690
Py_DECREF(rawdata);
16911691
return NULL;
16921692
}

numpy/core/src/multiarray/nditer_pywrap.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ NpyIter_GlobalFlagsConverter(PyObject *flags_in, npy_uint32 *flags)
129129
f = f_str;
130130
}
131131

132-
if (PyBytes_AsStringAndSize(f, &str, &length) == -1) {
132+
if (PyBytes_AsStringAndSize(f, &str, &length) < 0) {
133133
Py_DECREF(f);
134134
return 0;
135135
}
@@ -238,7 +238,7 @@ npyiter_order_converter(PyObject *order_in, NPY_ORDER *order)
238238
return ret;
239239
}
240240

241-
if (PyBytes_AsStringAndSize(order_in, &str, &length) == -1) {
241+
if (PyBytes_AsStringAndSize(order_in, &str, &length) < 0) {
242242
return 0;
243243
}
244244

@@ -300,7 +300,8 @@ NpyIter_OpFlagsConverter(PyObject *op_flags_in,
300300
f = f_str;
301301
}
302302

303-
if (PyBytes_AsStringAndSize(f, &str, &length) == -1) {
303+
if (PyBytes_AsStringAndSize(f, &str, &length) < 0) {
304+
PyErr_Clear();
304305
Py_DECREF(f);
305306
PyErr_SetString(PyExc_ValueError,
306307
"op_flags must be a tuple or array of per-op flag-tuples");

numpy/core/src/umath/ufunc_object.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,8 @@ static int get_ufunc_arguments(PyUFuncObject *ufunc,
927927
}
928928
#endif
929929

930-
if (PyBytes_AsStringAndSize(key, &str, &length) == -1) {
930+
if (PyBytes_AsStringAndSize(key, &str, &length) < 0) {
931+
PyErr_Clear();
931932
PyErr_SetString(PyExc_TypeError, "invalid keyword argument");
932933
goto fail;
933934
}

numpy/core/src/umath/ufunc_type_resolution.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,7 @@ type_tuple_type_resolver(PyUFuncObject *self,
20442044
type_tup = str_obj;
20452045
}
20462046

2047-
if (!PyBytes_AsStringAndSize(type_tup, &str, &length) < 0) {
2047+
if (PyBytes_AsStringAndSize(type_tup, &str, &length) < 0) {
20482048
Py_XDECREF(str_obj);
20492049
return -1;
20502050
}

0 commit comments

Comments
 (0)
0