From 54202fcaad727cadadc934a43d7138f0f9517d9f Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 18 Dec 2025 13:44:17 +0000 Subject: [PATCH] Check image size against available screen size properly, GitHub issue 4739. --- screen-write.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/screen-write.c b/screen-write.c index c95a9786..d25462df 100644 --- a/screen-write.c +++ b/screen-write.c @@ -2367,8 +2367,11 @@ screen_write_sixelimage(struct screen_write_ctx *ctx, struct sixel_image *si, u_int x, y, sx, sy, cx = s->cx, cy = s->cy, i, lines; struct sixel_image *new; + if (screen_size_y(s) == 1) + return; + sixel_size_in_cells(si, &x, &y); - if (x > screen_size_x(s) || y > screen_size_y(s)) { + if (x > screen_size_x(s) || y > screen_size_y(s) - 1) { if (x > screen_size_x(s) - cx) sx = screen_size_x(s) - cx; else @@ -2379,12 +2382,10 @@ screen_write_sixelimage(struct screen_write_ctx *ctx, struct sixel_image *si, sy = y; new = sixel_scale(si, 0, 0, 0, y - sy, sx, sy, 1); sixel_free(si); - si = new; - - /* Bail out if the image cannot be scaled. */ - if (si == NULL) + if (new == NULL) return; - sixel_size_in_cells(si, &x, &y); + sixel_size_in_cells(new, &x, &y); + si = new; } sy = screen_size_y(s) - cy;