From eb0ed43ce28273c0da4fad511009962776cbcb4b Mon Sep 17 00:00:00 2001 From: John Zaitseff Date: Mon, 6 Aug 2018 13:57:16 +1000 Subject: [PATCH] Bug fix: char may be unsigned on some platforms The function wctob() returns an int that can be -1; a conversion to unsigned char will make that value 0xFF. Although the "if" statement still works in this case, we should be more diligent in our programming. --- src/intf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/intf.c b/src/intf.c index 9898d21..d87131f 100644 --- a/src/intf.c +++ b/src/intf.c @@ -1763,7 +1763,7 @@ int getwch (WINDOW *win, wint_t *restrict wch) int ret = wget_wch(win, wch); if (ret == OK) { - char c = wctob(*wch); + int c = wctob(*wch); if ((c >= 0 && c < ' ') || c == 0x7F) { /* Make control characters (and DEL) appear to be similar to function keys. This assumes the KEY_xxx definitions do @@ -1771,7 +1771,7 @@ int getwch (WINDOW *win, wint_t *restrict wch) (due to the same codes being returned by getch()). We do not use iswcntrl() as certain additional Unicode characters are also control characters (eg, U+2028) */ - *wch = (unsigned char) c; + *wch = (wint_t) c; ret = KEY_CODE_YES; } } @@ -1835,11 +1835,11 @@ int getwch (WINDOW *win, wint_t *restrict wch) // A valid multibyte sequence memcpy(mbstate, &mbcopy, sizeof(mbstate_t)); - char c = wctob(val); + int c = wctob(val); if ((c >= 0 && c < ' ') || c == 0x7F) { /* Make control characters (and DEL) appear to be similar to function keys. */ - val = (unsigned char) c; + val = (wchar_t) c; ret = KEY_CODE_YES; } else { // An ordinary key