From 87040f6fd2d6913fbf1d48cdc9dd4ed7accc631b Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 23 Aug 2015 14:10:59 +0100 Subject: [PATCH] Fix an arithmetic error in the X font downloader cache. If you're trying to arrange that an array size is large enough for element n to exist, and you also want to round it up to the next multiple of 0x100, you must set the size to (n + 0x100) & ~0xFF, and not (n + 0xFF) & ~0xFF. Put another way, the number you have to round up is not n, but the minimum size n+1 that causes array[n] to exist. --- unix/gtkfont.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unix/gtkfont.c b/unix/gtkfont.c index 75800560..c8225134 100644 --- a/unix/gtkfont.c +++ b/unix/gtkfont.c @@ -634,7 +634,7 @@ static void x11font_cairo_cache_glyph(x11font_individual *xfi, int glyphindex) * principle that Unicode characters come in contiguous blocks * often used together */ int old_nglyphs = xfi->nglyphs; - xfi->nglyphs = (glyphindex + 0xFF) & ~0xFF; + xfi->nglyphs = (glyphindex + 0x100) & ~0xFF; xfi->glyphcache = sresize(xfi->glyphcache, xfi->nglyphs, struct cairo_cached_glyph);