1
0
mirror of https://github.com/openbsd/src.git synced 2026-04-29 00:27:11 +00:00

Clamp width to terminal width, also change calculation of end of screen

(it is OK to be outside the screen). Fixes problem reported by Dane
Jensen in GitHub issue 4969.
This commit is contained in:
nicm
2026-04-04 11:20:01 +00:00
parent 1329367c83
commit 4791559ae8

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: tty-draw.c,v 1.5 2026/03/23 08:48:32 nicm Exp $ */
/* $OpenBSD: tty-draw.c,v 1.6 2026/04/04 11:20:01 nicm Exp $ */
/*
* Copyright (c) 2026 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -143,6 +143,14 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
log_debug("%s: px=%u py=%u nx=%u atx=%u aty=%u", __func__, px, py, nx,
atx, aty);
/* There is no point in drawing more than the end of the terminal. */
if (atx >= tty->sx)
return;
if (atx + nx >= tty->sx)
nx = tty->sx - atx;
if (nx == 0)
return;
/*
* Clamp the width to cellsize - note this is not cellused, because
* there may be empty background cells after it (from BCE).
@@ -150,15 +158,8 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
cellsize = grid_get_line(gd, gd->hsize + py)->cellsize;
if (screen_size_x(s) > cellsize)
ex = cellsize;
else {
else
ex = screen_size_x(s);
if (px > ex)
return;
if (px + nx > ex)
nx = ex - px;
}
if (ex < nx)
ex = nx;
log_debug("%s: drawing %u-%u,%u (end %u) at %u,%u; defaults: fg=%d, "
"bg=%d", __func__, px, px + nx, py, ex, atx, aty, defaults->fg,
defaults->bg);
@@ -252,7 +253,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
}
/* Work out the the empty width. */
if (i >= ex)
if (px >= ex || i >= ex - px)
empty = 1;
else if (gcp->bg != last.bg)
empty = 0;