From: NeilBrown Date: Fri, 6 Oct 2023 22:02:48 +0000 (+1100) Subject: ncurses: don't look past the end of an image. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=079fd1b89fff0305d2533dc13a503166c862ae6e;p=edlib.git 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 --- 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);