From eb46f70db5c79bd3f711e4958b78cbf9ae91bc98 Mon Sep 17 00:00:00 2001 From: Pip Cet Date: Sun, 23 Jun 2019 08:02:18 +0000 Subject: [PATCH] Don't assume the width of xbm images is divisible by 8. --- src/image.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/image.c b/src/image.c index 866323ba6e..7ca6033697 100644 --- a/src/image.c +++ b/src/image.c @@ -3814,7 +3814,24 @@ xbm_load (struct frame *f, struct image *img) else if (STRINGP (data)) bits = SSDATA (data); else - bits = (char *) bool_vector_data (data); + { + if (img->width & 7) + { + int nbytes = (img->width + CHAR_BIT - 1) / CHAR_BIT; + Lisp_Object newdata = + Fmake_bool_vector (make_fixnum (img->height * nbytes * CHAR_BIT), Qnil); + + for (int y = 0; y < img->height; y++) + { + int i = y * nbytes * CHAR_BIT; + for (int j = y * img->width; j < (y+1) * img->width; i++, j++) + bool_vector_set (newdata, i, bool_vector_ref (data, j)); + } + + data = newdata; + } + bits = (char *) bool_vector_data (data); + } #ifdef HAVE_NTGUI { -- 2.20.1