From 4fb200a546ed54eb747c6e76992652d61baacb3b Mon Sep 17 00:00:00 2001 From: Xuekun Li Date: Tue, 2 May 2023 20:53:59 +0800 Subject: [PATCH] LibGUI: Fix crash on deleting word forward will crash when deleting at the end of line where the next line contains only punctuation and seperator characters, because TextDocument::first_word_break_after will return a wrong index of the next word break (+1 bigger than the correct index), thus RemoveTextCommand will try to remove a out-of-bound text range causing a crash. --- Userland/Libraries/LibGUI/TextDocument.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp index f3e225d025..0770cd41d6 100644 --- a/Userland/Libraries/LibGUI/TextDocument.cpp +++ b/Userland/Libraries/LibGUI/TextDocument.cpp @@ -791,7 +791,7 @@ TextPosition TextDocument::first_word_break_after(TextPosition const& position) auto view_between_target_and_index = line.view().substring_view(target.column(), *index - target.column()); if (should_continue_beyond_word(view_between_target_and_index)) { - target.set_column(*index + 1); + target.set_column(min(*index + 1, line.length())); continue; }