Skip to content

Commit e8ca2d8

Browse files
sobolevnserhiy-storchaka
authored andcommitted
pythongh-116714: Handle errors correctly in PyFloat_GetInfo (python#116715)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 0384a6f commit e8ca2d8

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Objects/floatobject.c

+13-8
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,18 @@ 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) SetFlag(PyLong_FromLong((FLAG)))
112+
#define SetDblFlag(FLAG) SetFlag(PyFloat_FromDouble((FLAG)))
105113

106114
SetDblFlag(DBL_MAX);
107115
SetIntFlag(DBL_MAX_EXP);
@@ -116,11 +124,8 @@ PyFloat_GetInfo(void)
116124
SetIntFlag(FLT_ROUNDS);
117125
#undef SetIntFlag
118126
#undef SetDblFlag
127+
#undef SetFlag
119128

120-
if (PyErr_Occurred()) {
121-
Py_CLEAR(floatinfo);
122-
return NULL;
123-
}
124129
return floatinfo;
125130
}
126131

0 commit comments

Comments
 (0)