8000 gh-111295: Fix timemodule.c not checking for errors when initializing · sobolevn/cpython@f7e89df · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit f7e89df

Browse files
committed
pythongh-111295: Fix timemodule.c not checking for errors when initializing
1 parent 8b44f3c commit f7e89df

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix :mod:`time` not checking for errors when initializing.

Modules/timemodule.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,13 @@ get_gmtoff(time_t t, struct tm *p)
17401740
static int
17411741
init_timezone(PyObject *m)
17421742
{
1743+
#define ADD_INT(NAME, VALUE) \
1744+
do { \
1745+
if (PyModule_AddIntConstant(m, NAME, VALUE) < 0) { \
1746+
return -1; \
1747+
} \
1748+
} while (0)
1749+
17431750
assert(!PyErr_Occurred());
17441751

17451752
/* This code moved from PyInit_time wholesale to allow calling it from
@@ -1763,13 +1770,13 @@ init_timezone(PyObject *m)
17631770
#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
17641771
tzset();
17651772
#endif
1766-
PyModule_AddIntConstant(m, "timezone", _Py_timezone);
1773+
ADD_INT("timezone", _Py_timezone);
17671774
#ifdef HAVE_ALTZONE
1768-
PyModule_AddIntConstant(m, "altzone", altzone);
1775+
ADD_INT("altzone", altzone);
17691776
#else
1770-
PyModule_AddIntConstant(m, "altzone", _Py_timezone-3600);
1777+
ADD_INT("altzone", _Py_timezone-3600);
17711778
#endif
1772-
PyModule_AddIntConstant(m, "daylight", _Py_daylight);
1779+
ADD_INT("daylight", _Py_daylight);
17731780
#ifdef MS_WINDOWS
17741781
TIME_ZONE_INFORMATION tzinfo = {0};
17751782
GetTimeZoneInformation(&tzinfo);
@@ -1828,20 +1835,21 @@ init_timezone(PyObject *m)
18281835
PyObject *tzname_obj;
18291836
if (janzone < julyzone) {
18301837
/* DST is reversed in the southern hemisphere */
1831-
PyModule_AddIntConstant(m, "timezone", julyzone);
1832-
PyModule_AddIntConstant(m, "altzone", janzone);
1833-
PyModule_AddIntConstant(m, "daylight", janzone != julyzone);
1838+
ADD_INT("timezone", julyzone);
1839+
ADD_INT("altzone", janzone);
1840+
ADD_INT("daylight", janzone != julyzone);
18341841
tzname_obj = Py_BuildValue("(zz)", julyname, janname);
18351842
} else {
1836-
PyModule_AddIntConstant(m, "timezone", janzone);
1837-
PyModule_AddIntConstant(m, "altzone", julyzone);
1838-
PyModule_AddIntConstant(m, "daylight", janzone != julyzone);
1843+
ADD_INT("timezone", janzone);
1844+
ADD_INT("altzone", julyzone);
1845+
ADD_INT("daylight", janzone != julyzone);
18391846
tzname_obj = Py_BuildValue("(zz)", janname, julyname);
18401847
}
18411848
if (PyModule_Add(m, "tzname", tzname_obj) < 0) {
18421849
return -1;
18431850
}
18441851
#endif // !HAVE_DECL_TZNAME
1852+
#undef ADD_INT
18451853

18461854
if (PyErr_Occurred()) {
18471855
return -1;

0 commit comments

Comments
 (0)
0