[Lldb-commits] [lldb] Fix a crash from character type confusion interaction with libedit (PR #75388)

Kevin Frei via lldb-commits lldb-commits at lists.llvm.org
Wed Dec 13 16:31:09 PST 2023


================
@@ -978,8 +978,14 @@ void Editline::DisplayCompletions(
       break;
 
     fprintf(editline.m_output_file, "More (Y/n/a): ");
-    char reply = 'n';
-    int got_char = el_getc(editline.m_editline, &reply);
+    // The type for the output and the type for the parameter are different,
+    // to allow interoperability with older versions of libedit. The container
+    // for the reply must be as wide as what our implementation is using,
+    // but libedit may use a narrower type depending on the build
+    // configuration.
+    EditLineGetCharType reply = L'n';
+    int got_char = el_wgetc(editline.m_editline,
----------------
kevinfrei wrote:

el_wgetc is #defined to el_getc if there's no wchar_t support (it's not at all consistent in this file, but I wanted to targeted fix for the crash). The core problem is actually with the #if code below the comment in the header:
```
#if LLDB_EDITLINE_USE_WCHAR || defined(EL_CLIENTDATA) || LLDB_HAVE_EL_RFUNC_T
using EditLineGetCharType = wchar_t;
#else
using EditLineGetCharType = char;
#endif
```

We set EditLineGetCharType to wchar_t, *even if you are building with `LLDB_EDITLINE_USE_WCHAR=0`* with newer versions of libedit (the ones that define EL_CLIENTDATA) so the function that reads a character (called from within libedit) is always reading a wchar_t *and writing it to the buffer that's backed by `&reply`*.

https://github.com/llvm/llvm-project/pull/75388


More information about the lldb-commits mailing list