From db34ee357d0a2abd5ae4adca954d82cf79e850ec Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 22 Dec 2023 00:44:24 +0330 Subject: [PATCH] LibLine: Avoid returning reference to cached suggestion This caused a dangling reference down the line, which lead to funny things like the following: > cd Bui[tab] > cd Bui^@^@ By returning a direct reference to the suggestion in question, we can be sure that the referenced object is alive until the next suggestion cycle. --- Userland/Libraries/LibLine/SuggestionManager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibLine/SuggestionManager.cpp b/Userland/Libraries/LibLine/SuggestionManager.cpp index 9e58306a93..b1fc2663d9 100644 --- a/Userland/Libraries/LibLine/SuggestionManager.cpp +++ b/Userland/Libraries/LibLine/SuggestionManager.cpp @@ -76,9 +76,10 @@ void SuggestionManager::previous() CompletionSuggestion const& SuggestionManager::suggest() { - m_last_shown_suggestion = m_suggestions[m_next_suggestion_index]; + auto const& suggestion = m_suggestions[m_next_suggestion_index]; m_selected_suggestion_index = m_next_suggestion_index; - return m_last_shown_suggestion; + m_last_shown_suggestion = suggestion; + return suggestion; } void SuggestionManager::set_current_suggestion_initiation_index(size_t index)