Skip to content

Commit 698e210

Browse files
OmarEmaraDevclayborg
authored andcommitted
[LLDB][GUI] Fix text field incorrect key handling
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. Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D108327
1 parent a0ed449 commit 698e210

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lldb/source/Core/IOHandlerCursesGUI.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,13 @@ class TextFieldDelegate : public FieldDelegate {
12081208

12091209
// True if the key represents a char that can be inserted in the field
12101210
// content, false otherwise.
1211-
virtual bool IsAcceptableChar(int key) { return isprint(key); }
1211+
virtual bool IsAcceptableChar(int key) {
1212+
// The behavior of isprint is undefined when the value is not representable
1213+
// as an unsigned char. So explicitly check for non-ascii key codes.
1214+
if (key > 127)
1215+
return false;
1216+
return isprint(key);
1217+
}
12121218

12131219
HandleCharResult FieldDelegateHandleChar(int key) override {
12141220
if (IsAcceptableChar(key)) {

0 commit comments

Comments
 (0)