From a1e7aa330cf50326b99a398293e582a551cbd8fb Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 18 May 2020 20:43:57 +0200 Subject: [PATCH] HackStudio: Don't use an OOB TextRange when looking for hovered text We could going +1 past the end of a TextDocumentLine here. This caused us to crash in the brave new world, so we could find it. :^) --- DevTools/HackStudio/Editor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DevTools/HackStudio/Editor.cpp b/DevTools/HackStudio/Editor.cpp index d813c40544..3e492caa74 100644 --- a/DevTools/HackStudio/Editor.cpp +++ b/DevTools/HackStudio/Editor.cpp @@ -234,7 +234,8 @@ void Editor::mousemove_event(GUI::MouseEvent& event) if (span.range.contains(text_position)) { auto adjusted_range = span.range; - adjusted_range.end().set_column(adjusted_range.end().column() + 1); + auto end_line_length = document().line(span.range.end().line()).length(); + adjusted_range.end().set_column(min(end_line_length, adjusted_range.end().column() + 1)); auto hovered_span_text = document().text_in_range(adjusted_range); #ifdef EDITOR_DEBUG dbg() << "Hovering: " << adjusted_range << " \"" << hovered_span_text << "\"";