]> granicus.if.org Git - python/commitdiff
Issue #28549: Fixed segfault in curses's addch() with ncurses6.
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 30 Oct 2016 20:52:06 +0000 (22:52 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 30 Oct 2016 20:52:06 +0000 (22:52 +0200)
Misc/NEWS
Modules/_cursesmodule.c

index 298d3aa64e2889a616cae8bf729c53778cfd6b3d..d7f3d28264a463893db45fe79d22d8d5e69b5d50 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -113,6 +113,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #28549: Fixed segfault in curses's addch() with ncurses6.
+
 - Issue #28449: tarfile.open() with mode "r" or "r:" now tries to open a tar
   file with compression before trying to open it without compression.  Otherwise
   it had 50% chance failed with ignore_zeros=True.
index 1c718a71f4ed9b8e81d59c710278d80f08ea7ca5..896d40d38e40af3746886ee8bb560beaad709777 100644 (file)
@@ -280,7 +280,7 @@ static int
 PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,
                           chtype *ch
 #ifdef HAVE_NCURSESW
-                          , cchar_t *wch
+                          , wchar_t *wch
 #endif
                           )
 {
@@ -298,8 +298,7 @@ PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,
                          PyUnicode_GET_LENGTH(obj));
             return 0;
         }
-        memset(wch->chars, 0, sizeof(wch->chars));
-        wch->chars[0] = buffer[0];
+        *wch = buffer[0];
         return 2;
 #else
         return PyCurses_ConvertToChtype(win, obj, ch);
@@ -597,7 +596,8 @@ curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y,
     int type;
     chtype cch;
 #ifdef HAVE_NCURSESW
-    cchar_t wch;
+    wchar_t wstr[2];
+    cchar_t wcval;
 #endif
     const char *funcname;
 
@@ -605,14 +605,15 @@ curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y,
       attr = A_NORMAL;
 
 #ifdef HAVE_NCURSESW
-    type = PyCurses_ConvertToCchar_t(cwself, ch, &cch, &wch);
+    type = PyCurses_ConvertToCchar_t(cwself, ch, &cch, wstr);
     if (type == 2) {
         funcname = "add_wch";
-        wch.attr = attr;
+        wstr[1] = L'\0';
+        setcchar(&wcval, wstr, attr, 0, NULL);
         if (coordinates_group)
-            rtn = mvwadd_wch(cwself->win,y,x, &wch);
+            rtn = mvwadd_wch(cwself->win,y,x, &wcval);
         else {
-            rtn = wadd_wch(cwself->win, &wch);
+            rtn = wadd_wch(cwself->win, &wcval);
         }
     }
     else