From 41707e02024b4c9ecc2fbb202fa4c7f3cb871fed Mon Sep 17 00:00:00 2001 From: Ray Chason Date: Tue, 27 Sep 2022 22:58:37 -0400 Subject: [PATCH] Fix wgetnstr with PDC_WIDE Casting an array of wchar_t to wint_t * works as intended only if wchar_t and wint_t have the same size. If they don't, wgetnstr will not work. Cast the elements to wchar_t instead. --- pdcurses/getstr.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pdcurses/getstr.c b/pdcurses/getstr.c index 603769f1..cc9f627b 100644 --- a/pdcurses/getstr.c +++ b/pdcurses/getstr.c @@ -72,12 +72,17 @@ int wgetnstr(WINDOW *win, char *str, int n) { #ifdef PDC_WIDE wchar_t wstr[MAXLINE + 1]; + wint_t wintstr[MAXLINE + 1]; + int i; if (n < 0 || n > MAXLINE) n = MAXLINE; - if (wgetn_wstr(win, (wint_t *)wstr, n) == ERR) + if (wgetn_wstr(win, wintstr, n) == ERR) return ERR; + for (i = 0; i < n; ++i) { + wstr[i] = (wchar_t)wintstr[i]; + } return PDC_wcstombs(str, wstr, n); #else