From 6833abf33cb168716bf57f9eb170a293fe918d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 5 Jan 2020 15:38:45 +0100 Subject: [PATCH] selection: foreach_selection_*: must wrap row number Fixes occasional crashes when we're at the end of the grid and selection wraps around. --- selection.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/selection.c b/selection.c index 9a574169..7ea146f7 100644 --- a/selection.c +++ b/selection.c @@ -74,7 +74,9 @@ foreach_selected_normal( } for (int r = start_row; r <= end_row; r++) { - struct row *row = term->grid->rows[r]; + size_t real_r = r & (term->grid->num_rows - 1); + struct row *row = term->grid->rows[real_r]; + assert(row != NULL); for (int c = start_col; c <= (r == end_row ? end_col : term->cols - 1); @@ -107,7 +109,9 @@ foreach_selected_block( }; for (int r = top_left.row; r <= bottom_right.row; r++) { - struct row *row = term->grid->rows[r]; + size_t real_r = r & (term->grid->num_rows - 1); + struct row *row = term->grid->rows[real_r]; + assert(row != NULL); for (int c = top_left.col; c <= bottom_right.col; c++) cb(term, row, &row->cells[c], data);