diff --git a/screen-write.c b/screen-write.c index 952e05e9..677a2b44 100644 --- a/screen-write.c +++ b/screen-write.c @@ -2139,8 +2139,8 @@ screen_write_collect_flush_line(struct screen_write_ctx *ctx, u_int y) struct screen_write_citem *ci, *tmp; struct screen_write_cline *cl = &s->write_list[y]; u_int last = UINT_MAX, items = 0, wsx, wsy; - u_int w_start, w_end, w_length, i; - int xoff, yoff, written; + u_int w_length, i; + int w_start, w_end, xoff, yoff, written; int r_start, r_end, c_start, c_end; struct tty_ctx ttyctx; struct visible_ranges *r; @@ -2179,16 +2179,18 @@ screen_write_collect_flush_line(struct screen_write_ctx *ctx, u_int y) c_start = ci->x; c_end = ci->x + ci->used; - if (c_start + xoff > r_end || c_end + xoff < r_start) + if (c_start + xoff >= r_end || c_end + xoff <= r_start) continue; if (r_start > c_start + xoff) - w_start = c_start + (r_start - c_start + xoff); + w_start = r_start - xoff; else w_start = c_start; if (c_end + xoff > r_end) - w_end = c_end - (c_end + xoff - r_end); + w_end = r_end - xoff; else w_end = c_end; + if (w_end <= w_start) + continue; w_length = w_end - w_start; if (w_length <= 0) continue;