mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-13 05:33:51 -04:00
search: fix infinite loop when highlighting all matches
find_next() did not always terminate correctly, causing search_matches_next() to never terminate, which finally leads to an infinite loop when rendering the search overlay surface, while finding all matches to highlight. The problem is that find_next(), after having found the initial matching characters, enters a nested while loop that tries to match the rest of the search criteria. This inner while loop did not check if we’ve reached the last cell, and happily continued past it (eventually wrappping around the scrollback buffer). Closes #1047
This commit is contained in:
parent
694938b85b
commit
0e9ebf433b
2 changed files with 16 additions and 1 deletions
13
search.c
13
search.c
|
|
@ -375,6 +375,13 @@ find_next(struct terminal *term, enum search_direction direction,
|
|||
|
||||
if (match_len != term->search.len) {
|
||||
/* Didn't match (completely) */
|
||||
|
||||
if (match_start_row == abs_end.row &&
|
||||
match_start_col == abs_end.col)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -563,10 +570,16 @@ search_matches_next(struct search_match_iterator *iter)
|
|||
xassert(match.end.row >= 0);
|
||||
xassert(match.end.row < term->rows);
|
||||
|
||||
/* Assert match end comes *after* the match start */
|
||||
xassert(match.end.row > match.start.row ||
|
||||
(match.end.row == match.start.row &&
|
||||
match.end.col >= match.start.col));
|
||||
|
||||
/* Assert the match starts at, or after, the iterator position */
|
||||
xassert(match.start.row > iter->start.row ||
|
||||
(match.start.row == iter->start.row &&
|
||||
match.start.col >= iter->start.col));
|
||||
|
||||
/* Continue at next column, next time */
|
||||
iter->start.row = match.start.row;
|
||||
iter->start.col = match.start.col + 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue