Fix crash by using texture in black square
authorH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 9 Feb 2018 16:11:27 +0000 (17:11 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 9 Feb 2018 16:11:27 +0000 (17:11 +0100)
When BlankSquare was called with square_color = 2 to black out a square
(as when drawing holdings), it tried to use a non-existent texture bitmap
for this when background textures were on, risking a segfault in Cairo.

draw.c

diff --git a/draw.c b/draw.c
index 79518a0..5190d56 100644 (file)
--- a/draw.c
+++ b/draw.c
@@ -774,7 +774,7 @@ DrawLogo (Option *opt, void *logo)
 static void
 BlankSquare (cairo_surface_t *dest, int x, int y, int color, ChessSquare piece, int fac)
 {   // [HGM] extra param 'fac' for forcing destination to (0,0) for copying to animation buffer
-    int x0, y0, texture = (useTexture & color+1) && CutOutSquare(x, y, &x0, &y0, color);
+    int x0, y0, texture = color < 2 && (useTexture & color+1) && CutOutSquare(x, y, &x0, &y0, color);
     cairo_t *cr;
 
     cr = cairo_create (dest);