Skip to content

Commit 81e9382

Browse files
committed
pythongh-116714: Handle errors correctly in PyFloat_GetInfo
1 parent ba82a24 commit 81e9382

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Objects/floatobject.c

+16-8
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,21 @@ PyFloat_GetInfo(void)
9898
return NULL;
9999
}
100100

101-
#define SetIntFlag(flag) \
102-
PyStructSequence_SET_ITEM(floatinfo, pos++, PyLong_FromLong(flag))
103-
#define SetDblFlag(flag) \
104-
PyStructSequence_SET_ITEM(floatinfo, pos++, PyFloat_FromDouble(flag))
101+
#define SetFlag(CALL) \
102+
do { \
103+
PyObject *flag = (CALL); \
104+
if (flag == NULL) { \
105+
Py_CLEAR(floatinfo); \
106+
return NULL; \
107+
} \
108+
PyStructSequence_SET_ITEM(floatinfo, pos++, flag); \
109+
} while (0)
110+
111+
#define SetIntFlag(FLAG) \
112+
SetFlag(PyLong_FromLong((FLAG)))
113+
114+
#define SetDblFlag(FLAG) \
115+
SetFlag(PyFloat_FromDouble((FLAG)))
105116

106117
SetDblFlag(DBL_MAX);
107118
SetIntFlag(DBL_MAX_EXP);
@@ -116,11 +127,8 @@ PyFloat_GetInfo(void)
116127
SetIntFlag(FLT_ROUNDS);
117128
#undef SetIntFlag
118129
#undef SetDblFlag
130+
#undef SetFlag
119131

120-
if (PyErr_Occurred()) {
121-
Py_CLEAR(floatinfo);
122-
return NULL;
123-
}
124132
return floatinfo;
125133
}
126134

0 commit comments

Comments
 (0)