From 8de5af5f9e4978f661f860cd41b89a1db07bc8ae Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sun, 3 Jun 2018 17:59:11 +0200 Subject: [PATCH] Fix off-by-one in complete_cmd_desc The substring constructor (string(str, pos)) includes pos, so we need to add one. Also be careful not to go over the length again. --- src/complete.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/complete.cpp b/src/complete.cpp index 3b3e8ef0b..653157887 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -545,7 +545,8 @@ void completer_t::complete_cmd_desc(const wcstring &str) { wcstring cmd; size_t pos = str.find_last_of(L'/'); if (pos != std::string::npos) { - cmd = wcstring(str, pos); + if (pos + 1 > str.length()) return; + cmd = wcstring(str, pos + 1); } else { cmd = str; }