Skip to content

Commit 647975c

Browse files
committed
avoid using PyNumber_AsSsize_t
1 parent 3db5577 commit 647975c

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Objects/bytesobject.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,16 +2898,13 @@ _PyBytes_FromSequence_lock_held(PyObject *x)
28982898

28992899
PyObject *const *items = PySequence_Fast_ITEMS(x);
29002900
for (Py_ssize_t i = 0; i < size; i++) {
2901-
if (!PyLong_Check(items[i])) {
2901+
Py_ssize_t value = PyLong_AsSsize_t(items[i]);
2902+
if (value == -1 && PyErr_Occurred()) {
29022903
PyBytesWriter_Discard(writer);
2904+
PyErr_Clear();
29032905
/* Py_None as a fallback sentinel to the slow path */
29042906
Py_RETURN_NONE;
29052907
}
2906-
Py_ssize_t value = PyNumber_AsSsize_t(items[i], NULL);
2907-
if (value == -1 && PyErr_Occurred()) {
2908-
PyBytesWriter_Discard(writer);
2909-
return NULL;
2910-
}
29112908

29122909
if (value < 0 || value >= 256) {
29132910
PyErr_SetString(PyExc_ValueError,

0 commit comments

Comments
 (0)