From 1c98c3a2a34682a6d0fa0077b5bcf563e97683ee Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 28 Aug 2026 08:11:08 +0000 Subject: [PATCH] Do not walk off end of grid lines if last line is wrapped, reported by Moe Khalilov. --- grid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grid.c b/grid.c index 36c99184f..0eb7c9920 100644 --- a/grid.c +++ b/grid.c @@ -1538,7 +1538,7 @@ grid_wrap_position(struct grid *gd, u_int px, u_int py, u_int *wx, u_int *wy) void grid_unwrap_position(struct grid *gd, u_int *px, u_int *py, u_int wx, u_int wy) { - u_int yy, ay = 0; + u_int yy, ay = 0, ey = gd->hsize + gd->sy - 1; for (yy = 0; yy < gd->hsize + gd->sy - 1; yy++) { if (ay == wy) @@ -1552,7 +1552,7 @@ grid_unwrap_position(struct grid *gd, u_int *px, u_int *py, u_int wx, u_int wy) * until we find the end or the line now containing wx. */ if (wx == UINT_MAX) { - while (gd->linedata[yy].flags & GRID_LINE_WRAPPED) + while (yy < ey && gd->linedata[yy].flags & GRID_LINE_WRAPPED) yy++; wx = gd->linedata[yy].cellused; } else {