From 675f3e56c82524cf45526d6856c906133f341c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 4 Oct 2020 14:05:37 +0200 Subject: [PATCH] =?UTF-8?q?sixel:=20overwrite-by-rectangle:=20assert=20six?= =?UTF-8?q?els=20don=E2=80=99t=20cross=20scrollback=20wrap-around?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sixel.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sixel.c b/sixel.c index 4de17c11..8c95e70b 100644 --- a/sixel.c +++ b/sixel.c @@ -372,23 +372,26 @@ _sixel_overwrite_by_rectangle( const int start = row; const int end = row + height - 1; + /* We should never generate scrollback wrapping sixels */ + assert(end < term->grid->num_rows); + const int scrollback_rel_start = rebase_row(term, start); tll_foreach(term->grid->sixel_images, it) { struct sixel *six = &it->item; const int six_start = six->pos.row; - const int six_end = (six_start + six->rows - 1) & (term->grid->num_rows - 1); + const int six_end = (six_start + six->rows - 1); const int six_scrollback_rel_end = rebase_row(term, six_end); + /* We should never generate scrollback wrapping sixels */ + assert(six_end < term->grid->num_rows); + if (six_scrollback_rel_end < scrollback_rel_start) { /* All remaining sixels are *before* our rectangle */ break; } - /* We should never generate scrollback wrapping sixels */ - assert(six_end >= six_start); - if ((start <= six_start && end >= six_start) || /* Crosses sixel start boundary */ (start <= six_end && end >= six_end) || /* Crosses sixel end boundary */ (start >= six_start && end <= six_end)) /* Fully within sixel range */