[lldb] Fix null pointer dereference in parsed command completion (#174868)

Fix a crash when tab-completing arguments for parsed commands that have
arguments but no options.

In `HandleArgumentCompletion`, `GetOptions()` returns `nullptr` when a
command has no options defined. The code was dereferencing this pointer
without a null check, causing a segfault when attempting tab completion.
This commit is contained in:
Alexandre Perez 2026-01-08 09:35:02 -08:00 committed by GitHub
parent 057c7a79e3
commit 3d6a96c091
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -2037,7 +2037,8 @@ public:
// option_element_vector:
Options *options = GetOptions();
auto defs = options->GetDefinitions();
auto defs = options ? options->GetDefinitions()
: llvm::ArrayRef<OptionDefinition>();
std::unordered_set<size_t> option_slots;
for (const auto &elem : option_vec) {

View File

@ -305,6 +305,13 @@ class ParsedCommandTestCase(TestBase):
matches.AppendList(["answer ", "correct_answer"], 2)
self.handle_completion(cmd_str, 1, matches, descriptions, False)
# Test completion for a command with arguments but NO options:
cmd_str = "one-arg-no-opt nonexistent_file_xyz"
matches.Clear()
descriptions.Clear()
matches.AppendString("")
self.handle_completion(cmd_str, 0, matches, descriptions, False)
# Now make sure get_repeat_command works properly:
# no-args turns off auto-repeat