From 222e580fa8b6ac768e993542effe1acda7d44c0a Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sat, 5 Feb 2022 14:36:34 +0330 Subject: [PATCH] Shell: Use strncmp() instead of string.compare() for name completions The "at most n bytes" behaviour of strncmp is required for this logic to work, this was overlooked in 5b64abe when converting Strings to StringViews, which lead to broken autocomplete. --- Userland/Shell/Shell.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp index 4a8afde4fe..9bf307e508 100644 --- a/Userland/Shell/Shell.cpp +++ b/Userland/Shell/Shell.cpp @@ -1453,7 +1453,12 @@ Vector Shell::complete_program_name(StringView name, cached_path.span(), name, nullptr, - [](auto& name, auto& program) { return name.compare(program.view()); }); + [](auto& name, auto& program) { + return strncmp( + name.characters_without_null_termination(), + program.characters(), + name.length()); + }); if (!match) return complete_path("", name, offset, ExecutableOnly::Yes);