diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-03-28 18:59:35 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-05-17 16:14:09 +0000 |
| commit | e415f858295ced5dbb1a0af961c4307c92b0c634 (patch) | |
| tree | e657ba760cf17fc2a42806423d01359eac02d423 | |
| parent | Merge branch 'box-drawing-use-pixman' (diff) | |
search: find_next(): proper check for scrollback wrap around
Besides disallowing matches that crosses the scrollback wrap-around,
this also fixes a crash when the trying to search beyond the last
output, when the scrollback history hasn’t yet been completely filled.
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | search.c | 19 |
2 files changed, 15 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 10ea7595..f1ac30d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -153,6 +153,7 @@ * PTY not being drained when the client application terminates. * `auto_left_margin` not being limited to `cub1` (https://codeberg.org/dnkl/foot/issues/441). +* Crash in scrollback search mode when searching beyond the last output. ### Contributors @@ -77,6 +77,16 @@ search_ensure_size(struct terminal *term, size_t wanted_size) return true; } +static bool +has_wrapped_around(const struct terminal *term, int abs_row_no) +{ + int scrollback_start = term->grid->offset + term->rows; + int rebased_row = abs_row_no - scrollback_start + term->grid->num_rows; + rebased_row &= term->grid->num_rows - 1; + + return rebased_row == 0; +} + static void search_cancel_keep_selection(struct terminal *term) { @@ -327,13 +337,12 @@ search_find_next(struct terminal *term) for (size_t i = 0; i < term->search.len;) { if (end_col >= term->cols) { - if (end_row + 1 > grid_row_absolute(term->grid, term->grid->offset + term->rows - 1)) { - /* Don't continue past end of the world */ - break; - } - end_row++; end_col = 0; + + if (has_wrapped_around(term, end_row)) + break; + row = term->grid->rows[end_row]; } |
