From e28e705d17438ffd9e8cc50322f8db9b9f37d9da Mon Sep 17 00:00:00 2001 From: William McBrine Date: Sat, 19 Jun 2021 12:12:19 -0400 Subject: [PATCH] Apparently, ReadConsoleInputA() does mistaken sign extension to 16 bits, rather than writing only the bottom 8 bits of the decoded key to the event structure. PDCurses, in turn, was reading the whole 16 bits even in narrow mode, resulting in corrupted "high-bit" characters in wincon. Potentially an issue since 3.0 (assuming ReadConsoleInputA() always did this?), but seemingly unreported (?) until now. Reported by Simon Sobisch. --- wincon/pdckbd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wincon/pdckbd.c b/wincon/pdckbd.c index fc634502..035eb87f 100644 --- a/wincon/pdckbd.c +++ b/wincon/pdckbd.c @@ -331,7 +331,12 @@ static int _get_key_count(void) static int _process_key_event(void) { - int key = (unsigned short)KEV.uChar.UnicodeChar; + int key = +#ifdef PDC_WIDE + KEV.uChar.UnicodeChar; +#else + KEV.uChar.AsciiChar; +#endif WORD vk = KEV.wVirtualKeyCode; DWORD state = KEV.dwControlKeyState;