diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-06-23 16:19:40 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-23 16:26:40 +0200 |
commit | 21ee0ad6fc14348ca35fa31a17c53dcec6563db8 (patch) | |
tree | b2421fc78372eecf0d13bed77e88f3a919572912 /Userland/Libraries | |
parent | c503a28e192958028f46cfa21225df51c986d8ba (diff) | |
download | serenity-21ee0ad6fc14348ca35fa31a17c53dcec6563db8.zip |
LibVT: Don't crash when clicking outside of the terminal's buffer area
When resizing a terminal window the number of columns may change.
Previously we assumed that this also affects lines which were in the
terminal's buffer while that is not necessarily true.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibVT/TerminalWidget.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index be866a0e10..49b2a8061d 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -592,8 +592,9 @@ VT::Position TerminalWidget::buffer_position_at(const Gfx::IntPoint& position) c column = 0; if (row >= m_terminal.rows()) row = m_terminal.rows() - 1; - if (column >= m_terminal.columns()) - column = m_terminal.columns() - 1; + auto& line = m_terminal.line(row); + if (column >= (int)line.length()) + column = line.length() - 1; row += m_scrollbar->value(); return { row, column }; } @@ -736,7 +737,7 @@ void TerminalWidget::doubleclick_event(GUI::MouseEvent& event) start_column = column; } - for (int column = position.column(); column < m_terminal.columns() && (line.code_point(column) == ' ') == want_whitespace; ++column) { + for (int column = position.column(); column < (int)line.length() && (line.code_point(column) == ' ') == want_whitespace; ++column) { end_column = column; } |