OmarEmaraDev created this revision. OmarEmaraDev added a reviewer: clayborg. Herald added a reviewer: teemperor. OmarEmaraDev requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
The isprint libc function was used to determine if the key code represents a printable character. The problem is that the specification leaves the behavior undefined if the key is not representable as an unsigned char, which is the case for many ncurses keys. This patch adds and explicit check for this undefined behavior and make it consistent. The llvm::isPrint function didn't work correctly for some reason, most likely because it takes a char instead of an int, which I guess makes it unsuitable for checking ncurses key codes. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D108327 Files: lldb/source/Core/IOHandlerCursesGUI.cpp Index: lldb/source/Core/IOHandlerCursesGUI.cpp =================================================================== --- lldb/source/Core/IOHandlerCursesGUI.cpp +++ lldb/source/Core/IOHandlerCursesGUI.cpp @@ -1208,7 +1208,13 @@ // True if the key represents a char that can be inserted in the field // content, false otherwise. - virtual bool IsAcceptableChar(int key) { return isprint(key); } + virtual bool IsAcceptableChar(int key) { + // The behavior of isprint is undefined when the value is not representable + // as an unsigned char. So explicitly check for non-ascii key codes. + if (key > 127) + return false; + return isprint(key); + } HandleCharResult FieldDelegateHandleChar(int key) override { if (IsAcceptableChar(key)) {
Index: lldb/source/Core/IOHandlerCursesGUI.cpp =================================================================== --- lldb/source/Core/IOHandlerCursesGUI.cpp +++ lldb/source/Core/IOHandlerCursesGUI.cpp @@ -1208,7 +1208,13 @@ // True if the key represents a char that can be inserted in the field // content, false otherwise. - virtual bool IsAcceptableChar(int key) { return isprint(key); } + virtual bool IsAcceptableChar(int key) { + // The behavior of isprint is undefined when the value is not representable + // as an unsigned char. So explicitly check for non-ascii key codes. + if (key > 127) + return false; + return isprint(key); + } HandleCharResult FieldDelegateHandleChar(int key) override { if (IsAcceptableChar(key)) {
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits