aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-04-23 10:28:12 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-04-24 18:17:37 +0000
commit082e242ce5c954c59f52a6878a6d3794694a1182 (patch)
tree69963d9392587fb37aaa04ff42f24d596ce6c164
parentsearch: matches_next: don’t wrap around grid->num_rows (diff)
search: matches_next: stop searching when start.row >= term->rows
As this means the last call to sarch_matches_next() found a match at the bottom of the view, and then set the iter’s *next* start position to a row outside the view. This is fine, but we need to handle it, by immediately stopping the iter.
-rw-r--r--search.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/search.c b/search.c
index 8f99fae7..337db697 100644
--- a/search.c
+++ b/search.c
@@ -539,7 +539,16 @@ search_matches_next(struct search_match_iterator *iter)
/* First, return the primary match */
match = term->selection.coords;
found = true;
- } else {
+ }
+
+ else if (iter->start.row >= term->rows) {
+ goto no_match;
+ }
+
+ else {
+ xassert(iter->start.row >= 0);
+ xassert(iter->start.row < term->rows);
+
struct coord abs_start = iter->start;
abs_start.row = grid_row_absolute_in_view(grid, abs_start.row);