[Lldb-commits] [lldb] 698e210 - [LLDB][GUI] Fix text field incorrect key handling

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 18 15:06:33 PDT 2021


Author: Omar Emara
Date: 2021-08-18T15:06:27-07:00
New Revision: 698e2106362add2bd3aca6f8ffebe9dd90a50529

URL: https://github.com/llvm/llvm-project/commit/698e2106362add2bd3aca6f8ffebe9dd90a50529
DIFF: https://github.com/llvm/llvm-project/commit/698e2106362add2bd3aca6f8ffebe9dd90a50529.diff

LOG: [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

Added: 
    

Modified: 
    lldb/source/Core/IOHandlerCursesGUI.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Core/IOHandlerCursesGUI.cpp b/lldb/source/Core/IOHandlerCursesGUI.cpp
index 0ae41dee7f9d..6e68c1d757c0 100644
--- a/lldb/source/Core/IOHandlerCursesGUI.cpp
+++ b/lldb/source/Core/IOHandlerCursesGUI.cpp
@@ -1208,7 +1208,13 @@ class TextFieldDelegate : public FieldDelegate {
 
   // 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)) {


        


More information about the lldb-commits mailing list