8000 [3.12] gh-116520: Fix error handling in `os_get_terminal_size_impl` i… · python/cpython@3f92cf2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f92cf2

Browse files
[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 b4b4e76) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent d38298a commit 3f92cf2

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Modules/posixmodule.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14340,12 +14340,23 @@ os_get_terminal_size_impl(PyObject *module, int fd)
1434014340
termsize = PyStructSequence_New((PyTypeObject *)TerminalSizeType);
1434114341
if (termsize == NULL)
1434214342
return NULL;
14343-
PyStructSequence_SET_ITEM(termsize, 0, PyLong_FromLong(columns));
14344-
PyStructSequence_SET_ITEM(termsize, 1, PyLong_FromLong(lines));
14345-
if (PyErr_Occurred()) {
14346-
Py_DECREF(termsize);
14347-
return NULL;
14348-
}
14343+
14344+
int pos = 0;
14345+
14346+
#define SET_TERMSIZE(CALL) \
14347+
do { \
14348+
PyObject *item = (CALL); \
14349+
if (item == NULL) { \
14350+
Py_DECREF(termsize); \
14351+
return NULL; \
14352+
} \
14353+
PyStructSequence_SET_ITEM(termsize, pos++, item); \
14354+
} while(0)
14355+
14356+
SET_TERMSIZE(PyLong_FromLong(columns));
14357+
SET_TERMSIZE(PyLong_FromLong(lines));
14358+
#undef SET_TERMSIZE
14359+
1434914360
return termsize;
1435014361
}
1435114362
#endif /* defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) */

0 commit comments

Comments
 (0)
0