[Python-checkins] cpython (merge 3.5 -> 3.6): Issue #28549: Fixed segfault in curses's addch() with ncurses6.

serhiy.storchaka python-checkins at python.org
Sun Oct 30 16:54:37 EDT 2016


https://hg.python.org/cpython/rev/382b3d19e9fc
changeset:   104836:382b3d19e9fc
branch:      3.6
parent:      104833:de8e83262644
parent:      104835:d06bf822585c
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Oct 30 22:53:09 2016 +0200
summary:
  Issue #28549: Fixed segfault in curses's addch() with ncurses6.

files:
  Misc/NEWS               |   2 ++
  Modules/_cursesmodule.c |  17 +++++++++--------
  2 files changed, 11 insertions(+), 8 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -30,6 +30,8 @@
 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.
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -280,7 +280,7 @@
 PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,
                           chtype *ch
 #ifdef HAVE_NCURSESW
-                          , cchar_t *wch
+                          , wchar_t *wch
 #endif
                           )
 {
@@ -298,8 +298,7 @@
                          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 @@
     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 @@
       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

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list