From 079fd1b89fff0305d2533dc13a503166c862ae6e Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 7 Oct 2023 09:02:48 +1100 Subject: [PATCH] ncurses: don't look past the end of an image. If the image is an odd number of rows, we need to use something else for the last row displayed. Signed-off-by: NeilBrown --- display-ncurses.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/display-ncurses.c b/display-ncurses.c index 84f14022..55c21c21 100644 --- a/display-ncurses.c +++ b/display-ncurses.c @@ -1048,11 +1048,15 @@ DEF_CB(nc_draw_image_cb) for (i = 0; i < dii->h; i+= 2) { static const wint_t hilo = 0x2580; /* L'▀' */ + static unsigned char blk[4] = "\0\0\0"; for (j = 0; j < dii->w ; j+= 1) { unsigned char *p1 = buf + i*dii->w*4 + j*4; - unsigned char *p2 = buf + (i+1)*dii->w*4 + j*4; - int rgb1[3] = { p1[0]*1000/255, p1[1]*1000/255, p1[2]*1000/255 }; - int rgb2[3] = { p2[0]*1000/255, p2[1]*1000/255, p2[2]*1000/255 }; + unsigned char *p2 = i + 1 < dii->h ? + buf + (i+1)*dii->w*4 + j*4 : blk; + int rgb1[3] = { p1[0]*1000/255, p1[1]*1000/255, + p1[2]*1000/255 }; + int rgb2[3] = { p2[0]*1000/255, p2[1]*1000/255, + p2[2]*1000/255 }; int fg = find_col(dd, rgb1); int bg = find_col(dd, rgb2); -- 2.39.5