Skip to content

Commit

Permalink
gh-116520: Fix error handling in os_get_terminal_size_impl in `posi…
Browse files Browse the repository at this point in the history
…xmodule` (#116521)
  • Loading branch information
sobolevn committed Mar 9, 2024
1 parent 03f86b1 commit b4b4e76
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions Modules/posixmodule.c
Expand Up @@ -14981,12 +14981,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) */
Expand Down

0 comments on commit b4b4e76

Please sign in to comment.