llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Walter Erquinigo (walter-erquinigo)

<details>
<summary>Changes</summary>

https://github.com/modularml/mojo/issues/1796 discovered that if you try to 
complete a space-only line in the REPL on Linux, LLDB crashes. I suspect that 
editline doesn't behave the same way on linux and on darwin, because I can't 
replicate this on darwin.

Adding a boundary check in the completion code prevents the crash from 
happening.

---
Full diff: https://github.com/llvm/llvm-project/pull/83203.diff


1 Files Affected:

- (modified) lldb/source/Host/common/Editline.cpp (+4-1) 


``````````diff
diff --git a/lldb/source/Host/common/Editline.cpp 
b/lldb/source/Host/common/Editline.cpp
index ce707e530d008b..e66271e8a6ee99 100644
--- a/lldb/source/Host/common/Editline.cpp
+++ b/lldb/source/Host/common/Editline.cpp
@@ -1029,8 +1029,11 @@ unsigned char Editline::TabCommand(int ch) {
     case CompletionMode::Normal: {
       std::string to_add = completion.GetCompletion();
       // Terminate the current argument with a quote if it started with a 
quote.
-      if (!request.GetParsedLine().empty() && 
request.GetParsedArg().IsQuoted())
+      Args &parsedLine = request.GetParsedLine();
+      if (!parsedLine.empty() && request.GetCursorIndex() < parsedLine.size() 
&&
+          request.GetParsedArg().IsQuoted()) {
         to_add.push_back(request.GetParsedArg().GetQuoteChar());
+      }
       to_add.push_back(' ');
       el_deletestr(m_editline, request.GetCursorArgumentPrefix().size());
       el_insertstr(m_editline, to_add.c_str());

``````````

</details>


https://github.com/llvm/llvm-project/pull/83203
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to