summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-03-09 11:36:02 (GMT)
committerGitHub <noreply@github.com>2024-03-09 11:36:02 (GMT)
commit3f92cf272e19086466add674585a9aa324334e0d (patch)
tree6ffd644f3637202f89c485de80915ea154220292 /Modules/posixmodule.c
parentd38298a9ba1663fe7c9ea5a765dbdb0c6c370f54 (diff)
downloadcpython-3f92cf272e19086466add674585a9aa324334e0d.zip
cpython-3f92cf272e19086466add674585a9aa324334e0d.tar.gz
cpython-3f92cf272e19086466add674585a9aa324334e0d.tar.bz2
[3.12] gh-116520: Fix error handling in `os_get_terminal_size_impl` in `posixmodule` (GH-116521) (#116539)
gh-116520: Fix error handling in `os_get_terminal_size_impl` in `posixmodule` (GH-116521) (cherry picked from commit b4b4e764a798bab60324871074ce4cdebb9d01bb) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index e64f000..865c70c 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -14340,12 +14340,23 @@ os_get_terminal_size_impl(PyObject *module, int fd)
termsize = PyStructSequence_New((PyTypeObject *)TerminalSizeType);
if (termsize == NULL)
return NULL;
- PyStructSequence_SET_ITEM(termsize, 0, PyLong_FromLong(columns));
- PyStructSequence_SET_ITEM(termsize, 1, PyLong_FromLong(lines));
- if (PyErr_Occurred()) {
- Py_DECREF(termsize);
- return NULL;
- }
+
+ int pos = 0;
+
+#define SET_TERMSIZE(CALL) \
+ do { \
+ PyObject *item = (CALL); \
+ if (item == NULL) { \
+ Py_DECREF(termsize); \
+ return NULL; \
+ } \
+ PyStructSequence_SET_ITEM(termsize, pos++, item); \
+ } while(0)
+
+ SET_TERMSIZE(PyLong_FromLong(columns));
+ SET_TERMSIZE(PyLong_FromLong(lines));
+#undef SET_TERMSIZE
+
return termsize;
}
#endif /* defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) */