Skip to content

Commit c08c7b1

Browse files
committed
gh-148119: Refactor get_type_attr_as_size to improve error handling in structseq.c
1 parent 985216c commit c08c7b1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Objects/structseq.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,23 @@ static Py_ssize_t
2828
get_type_attr_as_size(PyTypeObject *tp, PyObject *name)
2929
{
3030
PyObject *v = PyDict_GetItemWithError(_PyType_GetDict(tp), name);
31-
if (v == NULL && !PyErr_Occurred()) {
31+
32+
if (v == NULL) {
33+
if (PyErr_Occurred()) {
34+
return -1;
35+
}
3236
PyErr_Format(PyExc_TypeError,
3337
"Missed attribute '%U' of type %s",
3438
name, tp->tp_name);
3539
return -1;
3640
}
37-
return PyLong_AsSsize_t(v);
41+
42+
Py_ssize_t result = PyLong_AsSsize_t(v);
43+
if (result == -1 && PyErr_Occurred()) {
44+
return -1;
45+
}
46+
47+
return result;
3848
}
3949

4050
#define VISIBLE_SIZE(op) Py_SIZE(op)

0 commit comments

Comments
 (0)