From c5e0c5598453cedece3fac212a519e5c0c185f37 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 10 Sep 2024 20:08:28 +0300 Subject: [PATCH] gh-123913: Fix `NULL` handling in `_curses_initscr_impl` of `_cursesmodule` --- Modules/_cursesmodule.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index b5854e8c33f28a..932c059881574a 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -3266,7 +3266,6 @@ _curses_initscr_impl(PyObject *module) /*[clinic end generated code: output=619fb68443810b7b input=514f4bce1821f6b5]*/ { WINDOW *win; - PyCursesWindowObject *winobj; if (initialised) { wrefresh(stdscr); @@ -3362,9 +3361,12 @@ _curses_initscr_impl(PyObject *module) SetDictInt("LINES", LINES); SetDictInt("COLS", COLS); - winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL); - screen_encoding = winobj->encoding; - return (PyObject *)winobj; + PyObject *winobj = PyCursesWindow_New(win, NULL); + if (winobj == NULL) { + return NULL; + } + screen_encoding = ((PyCursesWindowObject *) winobj)->encoding; + return winobj; } /*[clinic input]