search: matches_next: don’t wrap around grid->num_rows

When bumping the iter’s start.row, we’re working with view-local
coordinates. That is, 0 >= row < term->rows.

This means it is wrong to and with grid->num_rows - 1, because a),
‘row’ should **never** be that big. And b), if we do, we’ll just end
up in an infinite loop, where the next call to matches_next() just
starts over from the beginning again (and eventually hitting the exact
same place that got us started).
This commit is contained in:
Daniel Eklöf 2022-04-23 12:25:21 +02:00
parent f7c29ee394
commit d068e821d6
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -580,10 +580,14 @@ search_matches_next(struct search_match_iterator *iter)
if (iter->start.col >= term->cols) {
iter->start.col = 0;
iter->start.row++;
iter->start.row &= grid->num_rows - 1;
iter->start.row++; /* Overflow is caught in next iteration */
}
xassert(iter->start.row >= 0);
xassert(iter->start.row <= term->rows);
xassert(iter->start.col >= 0);
xassert(iter->start.col < term->cols);
if (match.start.row == term->search.match.row &&
match.start.col == term->search.match.col)
{