diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2022-04-23 10:25:21 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2022-04-24 18:17:37 +0000 |
| commit | d068e821d60dc9d9ae606969010b087040b98b59 (patch) | |
| tree | ee40d784e0b1ffe46b880bceabf9d023ca0c7f2f | |
| parent | search: maches_next: assert match coordinates are valid (diff) | |
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).
| -rw-r--r-- | search.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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) { |
