Skip to content

Commit b4b4e76

Browse files
authored
gh-116520: Fix error handling in os_get_terminal_size_impl in posixmodule (#116521)
1 parent 03f86b1 commit b4b4e76

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Modules/posixmodule.c

+17-6
Original file line numberDiff line numberDiff line change
@@ -14981,12 +14981,23 @@ os_get_terminal_size_impl(PyObject *module, int fd)
1498114981
termsize = PyStructSequence_New((PyTypeObject *)TerminalSizeType);
1498214982
if (termsize == NULL)
1498314983
return NULL;
14984-
PyStructSequence_SET_ITEM(termsize, 0, PyLong_FromLong(columns));
14985-
PyStructSequence_SET_ITEM(termsize, 1, PyLong_FromLong(lines));
14986-
if (PyErr_Occurred()) {
14987-
Py_DECREF(termsize);
14988-
return NULL;
14989-
}
14984+
14985+
int pos = 0;
14986+
14987+
#define SET_TERMSIZE(CALL) \
14988+
do { \
14989+
PyObject *item = (CALL); \
14990+
if (item == NULL) { \
14991+
Py_DECREF(termsize); \
14992+
return NULL; \
14993+
} \
14994+
PyStructSequence_SET_ITEM(termsize, pos++, item); \
14995+
} while(0)
14996+
14997+
SET_TERMSIZE(PyLong_FromLong(columns));
14998+
SET_TERMSIZE(PyLong_FromLong(lines));
14999+
#undef SET_TERMSIZE
15000+
1499015001
return termsize;
1499115002
}
1499215003
#endif /* defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) */

0 commit comments

Comments
 (0)