Skip to content

Commit 0bcd89b

Browse files
Issue #28549: Fixed segfault in curses's addch() with ncurses6.
1 parent a89d22a commit 0bcd89b

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ Core and Builtins
113113
Library
114114
-------
115115

116+
- Issue #28549: Fixed segfault in curses's addch() with ncurses6.
117+
116118
- Issue #28449: tarfile.open() with mode "r" or "r:" now tries to open a tar
117119
file with compression before trying to open it without compression. Otherwise
118120
it had 50% chance failed with ignore_zeros=True.

Modules/_cursesmodule.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static int
280280
PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,
281281
chtype *ch
282282
#ifdef HAVE_NCURSESW
283-
, cchar_t *wch
283+
, wchar_t *wch
284284
#endif
285285
)
286286
{
@@ -298,8 +298,7 @@ PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,
298298
PyUnicode_GET_LENGTH(obj));
299299
return 0;
300300
}
301-
memset(wch->chars, 0, sizeof(wch->chars));
302-
wch->chars[0] = buffer[0];
301+
*wch = buffer[0];
303302
return 2;
304303
#else
305304
return PyCurses_ConvertToChtype(win, obj, ch);
@@ -597,22 +596,24 @@ curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y,
597596
int type;
598597
chtype cch;
599598
#ifdef HAVE_NCURSESW
600-
cchar_t wch;
599+
wchar_t wstr[2];
600+
cchar_t wcval;
601601
#endif
602602
const char *funcname;
603603

604604
if (!attr_group)
605605
attr = A_NORMAL;
606606

607607
#ifdef HAVE_NCURSESW
608-
type = PyCurses_ConvertToCchar_t(cwself, ch, &cch, &wch);
608+
type = PyCurses_ConvertToCchar_t(cwself, ch, &cch, wstr);
609609
if (type == 2) {
610610
funcname = "add_wch";
611-
wch.attr = attr;
611+
wstr[1] = L'\0';
612+
setcchar(&wcval, wstr, attr, 0, NULL);
612613
if (coordinates_group)
613-
rtn = mvwadd_wch(cwself->win,y,x, &wch);
614+
rtn = mvwadd_wch(cwself->win,y,x, &wcval);
614615
else {
615-
rtn = wadd_wch(cwself->win, &wch);
616+
rtn = wadd_wch(cwself->win, &wcval);
616617
}
617618
}
618619
else

0 commit comments

Comments
 (0)