From 6b513ca97e56adaabd1aa867091564ebd5614b4f Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Wed, 15 Apr 2020 18:26:11 +0430 Subject: [PATCH] LibLine: Avoid crashing if given empty suggestions --- Libraries/LibLine/Editor.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp index 5a5c05ec28b..71e5f0a79d7 100644 --- a/Libraries/LibLine/Editor.cpp +++ b/Libraries/LibLine/Editor.cpp @@ -153,7 +153,10 @@ String Editor::get_line(const String& prompt) auto reverse_tab = false; auto increment_suggestion_index = [&] { - m_next_suggestion_index = (m_next_suggestion_index + 1) % m_suggestions.size(); + if (m_suggestions.size()) + m_next_suggestion_index = (m_next_suggestion_index + 1) % m_suggestions.size(); + else + m_next_suggestion_index = 0; }; auto decrement_suggestion_index = [&] { if (m_next_suggestion_index == 0)