Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 23c17f3

Browse filesBrowse files
authored
[3.11] gh-116326: Handler errors correctly in getwindowsversion in sysmodule (GH-116339) (#116388)
(cherry picked from commit c91bdf8)
1 parent 4637a1f commit 23c17f3
Copy full SHA for 23c17f3

File tree

Expand file treeCollapse file tree

1 file changed

+25
-14
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-14
lines changed

‎Python/sysmodule.c

Copy file name to clipboardExpand all lines: Python/sysmodule.c
+25-14Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,15 +1479,24 @@ sys_getwindowsversion_impl(PyObject *module)
14791479
if (version == NULL)
14801480
return NULL;
14811481

1482-
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwMajorVersion));
1483-
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwMinorVersion));
1484-
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwBuildNumber));
1485-
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwPlatformId));
1486-
PyStructSequence_SET_ITEM(version, pos++, PyUnicode_FromWideChar(ver.szCSDVersion, -1));
1487-
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wServicePackMajor));
1488-
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wServicePackMinor));
1489-
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wSuiteMask));
1490-
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wProductType));
1482+
#define SET_VERSION_INFO(CALL) \
1483+
do { \
1484+
PyObject *item = (CALL); \
1485+
if (item == NULL) { \
1486+
goto error; \
1487+
} \
1488+
PyStructSequence_SET_ITEM(version, pos++, item); \
1489+
} while(0)
1490+
1491+
SET_VERSION_INFO(PyLong_FromLong(ver.dwMajorVersion));
1492+
SET_VERSION_INFO(PyLong_FromLong(ver.dwMinorVersion));
1493+
SET_VERSION_INFO(PyLong_FromLong(ver.dwBuildNumber));
1494+
SET_VERSION_INFO(PyLong_FromLong(ver.dwPlatformId));
1495+
SET_VERSION_INFO(PyUnicode_FromWideChar(ver.szCSDVersion, -1));
1496+
SET_VERSION_INFO(PyLong_FromLong(ver.wServicePackMajor));
1497+
SET_VERSION_INFO(PyLong_FromLong(ver.wServicePackMinor));
1498+
SET_VERSION_INFO(PyLong_FromLong(ver.wSuiteMask));
1499+
SET_VERSION_INFO(PyLong_FromLong(ver.wProductType));
14911500

14921501
realMajor = ver.dwMajorVersion;
14931502
realMinor = ver.dwMinorVersion;
@@ -1514,17 +1523,19 @@ sys_getwindowsversion_impl(PyObject *module)
15141523
}
15151524
PyMem_RawFree(verblock);
15161525
}
1517-
PyStructSequence_SET_ITEM(version, pos++, Py_BuildValue("(kkk)",
1526+
SET_VERSION_INFO(Py_BuildValue("(kkk)",
15181527
realMajor,
15191528
realMinor,
15201529
realBuild
15211530
));
15221531

1523-
if (PyErr_Occurred()) {
1524-
Py_DECREF(version);
1525-
return NULL;
1526-
}
1532+
#undef SET_VERSION_INFO
1533+
15271534
return version;
1535+
1536+
error:
1537+
Py_DECREF(version);
1538+
return NULL;
15281539
}
15291540

15301541
#pragma warning(pop)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.