[cairo-commit] 12 commits - boilerplate/cairo-boilerplate-xlib.c boilerplate/xmalloc.c src/cairo-image-surface.c src/cairoint.h src/cairo-path-stroke.c src/cairo-pattern.c src/cairo-pdf-surface.c src/cairo-pen.c src/cairo-png.c src/cairo-truetype-subset.c src/cairo-xlib-surface.c

Chris Wilson ickle at kemper.freedesktop.org
Thu Aug 16 08:10:57 PDT 2007


 boilerplate/cairo-boilerplate-xlib.c |   16 ++++++++++++----
 boilerplate/xmalloc.c                |    6 +++---
 src/cairo-image-surface.c            |   18 +++++++++---------
 src/cairo-path-stroke.c              |   24 ++++++------------------
 src/cairo-pattern.c                  |    4 ++--
 src/cairo-pdf-surface.c              |   13 ++++++++-----
 src/cairo-pen.c                      |   31 +++++++++----------------------
 src/cairo-png.c                      |   21 ++++++++++++---------
 src/cairo-truetype-subset.c          |   15 +++++++++------
 src/cairo-xlib-surface.c             |    9 +++++++--
 src/cairoint.h                       |    4 ++--
 11 files changed, 79 insertions(+), 82 deletions(-)

New commits:
diff-tree 507d7ee09951a35df8b80f0e1507ba17dbd9bfa9 (from 85d911d86c9f1dd55d79b7c429ad2b617ec345d1)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jun 27 12:34:35 2007 +0100

    [cairo-xlib-surface] Avoid a malloc(0).
    
    Avoid a zero byte allocation (potentially returning NULL) for an array
    of 0 trapezoids.

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 9d68a86..4c4b561 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -1626,11 +1626,14 @@ _create_trapezoid_mask (cairo_xlib_surfa
      * the servers that have XRenderAddTraps().
      */
     mask_picture = _create_a8_picture (dst, &transparent, width, height, FALSE);
-    solid_picture = _create_a8_picture (dst, &solid, width, height, TRUE);
+    if (num_traps == 0)
+	return mask_picture;
 
     offset_traps = _cairo_malloc_ab (num_traps, sizeof (XTrapezoid));
-    if (!offset_traps)
+    if (!offset_traps) {
+	XRenderFreePicture (dst->dpy, mask_picture);
 	return None;
+    }
 
     for (i = 0; i < num_traps; i++) {
 	offset_traps[i].top = _cairo_fixed_to_16_16(traps[i].top) - 0x10000 * dst_y;
@@ -1645,6 +1648,8 @@ _create_trapezoid_mask (cairo_xlib_surfa
 	offset_traps[i].right.p2.y = _cairo_fixed_to_16_16(traps[i].right.p2.y) - 0x10000 * dst_y;
     }
 
+    solid_picture = _create_a8_picture (dst, &solid, width, height, TRUE);
+
     XRenderCompositeTrapezoids (dst->dpy, PictOpAdd,
 				solid_picture, mask_picture,
 				pict_format,
diff-tree 85d911d86c9f1dd55d79b7c429ad2b617ec345d1 (from 7332a5e9949ca19869b003fe5a0a777adac41307)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jun 27 08:05:35 2007 +0100

    [cairo-image-surface] Avoid malloc(0)
    
    Special case width==0, height==0 to avoid allocating a 0 byte image.

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 553433c..9f933e2 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -921,6 +921,9 @@ _cairo_image_surface_composite_trapezoid
 	pixman_traps[i].right.p2.y = _cairo_fixed_to_16_16 (traps[i].right.p2.y);
     }
 
+    if (height == 0 || width == 0)
+	return CAIRO_STATUS_SUCCESS;
+
     /* Special case adding trapezoids onto a mask surface; we want to avoid
      * creating an intermediate temporary mask unnecessarily.
      *
diff-tree 7332a5e9949ca19869b003fe5a0a777adac41307 (from 56e505298c0f5de360380ca7e968baa0e60ac828)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jun 27 11:32:50 2007 +0100

    [boilerplate/xmalloc] Special case malloc(0) and friends.
    
    malloc(0) can return NULL so double check the requested size before
    exiting with an out-of-memory error.

diff --git a/boilerplate/xmalloc.c b/boilerplate/xmalloc.c
index ddd5ccc..c2cbe23 100644
--- a/boilerplate/xmalloc.c
+++ b/boilerplate/xmalloc.c
@@ -36,7 +36,7 @@ xmalloc (size_t size)
     void *buf;
 
     buf = malloc (size);
-    if (!buf) {
+    if (buf == NULL && size != 0) {
 	CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting.\n");
 	exit (1);
     }
@@ -50,7 +50,7 @@ xcalloc (size_t nmemb, size_t size)
     void *buf;
 
     buf = calloc (nmemb, size);
-    if (!buf) {
+    if (buf == NULL && nmemb != 0 && size != 0) {
 	CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting\n");
 	exit (1);
     }
@@ -62,7 +62,7 @@ void *
 xrealloc (void *buf, size_t size)
 {
     buf = realloc (buf, size);
-    if (!buf) {
+    if (buf == NULL && size != 0) {
 	CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting\n");
 	exit (1);
     }
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index b9c4748..553433c 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -922,7 +922,7 @@ _cairo_image_surface_composite_trapezoid
     }
 
     /* Special case adding trapezoids onto a mask surface; we want to avoid
-     * creating an intermediate temporary mask unecessarily.
+     * creating an intermediate temporary mask unnecessarily.
      *
      * We make the assumption here that the portion of the trapezoids
      * contained within the surface is bounded by [dst_x,dst_y,width,height];
diff-tree 56e505298c0f5de360380ca7e968baa0e60ac828 (from 7bd1d5ba3d081ae188fe7f8bc346071d0b8d2278)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jun 27 23:01:44 2007 +0100

    [cairo-truetype-subset] Avoid malloc(0).
    
    Avoid attempting to allocate a zero length subset as malloc(0) may return
    NULL.

diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index 7f168a5..528f639 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -931,13 +931,16 @@ _cairo_truetype_subset_init (cairo_truet
     truetype_subset->ascent = (double)font->base.ascent/font->base.units_per_em;
     truetype_subset->descent = (double)font->base.descent/font->base.units_per_em;
 
-    truetype_subset->data = malloc (length);
-    if (truetype_subset->data == NULL) {
-	status = CAIRO_STATUS_NO_MEMORY;
-	goto fail3;
-    }
+    if (length) {
+	truetype_subset->data = malloc (length);
+	if (truetype_subset->data == NULL) {
+	    status = CAIRO_STATUS_NO_MEMORY;
+	    goto fail3;
+	}
 
-    memcpy (truetype_subset->data, data, length);
+	memcpy (truetype_subset->data, data, length);
+    } else
+	truetype_subset->data = NULL;
     truetype_subset->data_length = length;
 
     if (num_strings) {
diff-tree 7bd1d5ba3d081ae188fe7f8bc346071d0b8d2278 (from 06134df0d0670a7d00d58ebd7a20ba7174f56d16)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Jul 3 14:14:56 2007 +0100

    [cairo-png] Protect against malloc(0).
    
    Avoid calling malloc(0) for an empty image.

diff --git a/src/cairo-png.c b/src/cairo-png.c
index 761fb3f..eaecbbd 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -114,7 +114,7 @@ write_png (cairo_surface_t	*surface,
     png_struct *png;
     png_info *info;
     png_time pt;
-    png_byte **rows;
+    png_byte **rows = NULL;
     png_color_16 white;
     int png_color_type;
     int depth;
@@ -128,14 +128,16 @@ write_png (cairo_surface_t	*surface,
     else if (status != CAIRO_STATUS_SUCCESS)
 	return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
 
-    rows = _cairo_malloc_ab (image->height, sizeof(png_byte*));
-    if (rows == NULL) {
-        status = CAIRO_STATUS_NO_MEMORY;
-	goto BAIL1;
-    }
+    if (image->height && image->width) {
+	rows = _cairo_malloc_ab (image->height, sizeof(png_byte*));
+	if (rows == NULL) {
+	    status = CAIRO_STATUS_NO_MEMORY;
+	    goto BAIL1;
+	}
 
-    for (i = 0; i < image->height; i++)
-	rows[i] = (png_byte *) image->data + i * image->stride;
+	for (i = 0; i < image->height; i++)
+	    rows[i] = (png_byte *) image->data + i * image->stride;
+    }
 
     png = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL,
 	                           png_simple_error_callback,
@@ -208,7 +210,8 @@ write_png (cairo_surface_t	*surface,
     if (image->format == CAIRO_FORMAT_RGB24)
 	png_set_filler (png, 0, PNG_FILLER_AFTER);
 
-    png_write_image (png, rows);
+    if (rows)
+	png_write_image (png, rows);
     png_write_end (png, info);
 
 BAIL3:
diff-tree 06134df0d0670a7d00d58ebd7a20ba7174f56d16 (from 76b871d710cd81bee5fe7c2f6175f8d678ebeea5)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jul 4 19:11:29 2007 +0100

    [cairo-pdf-surface] Check for errors during compression.
    
    Check status return from zlib's compress().

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 55279a6..f2fb802 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -680,7 +680,10 @@ compress_dup (const void *data, unsigned
     if (compressed == NULL)
 	return NULL;
 
-    compress (compressed, compressed_size, data, data_size);
+    if (compress (compressed, compressed_size, data, data_size) != Z_OK) {
+	free (compressed);
+	compressed = NULL;
+    }
 
     return compressed;
 }
diff-tree 76b871d710cd81bee5fe7c2f6175f8d678ebeea5 (from 4e39e30d83fc1866a44f0b746c406ee2efb3bf6a)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Aug 16 15:29:11 2007 +0100

    [cairo-image-surface] Remove status return for hard-coded CAIRO_STATUS_SUCCESS.
    
    Remove the status return if the function can only return
    CAIRO_STATUS_SUCCESS, and remove the then surplus conditionals.

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index dfdb7fb..b9c4748 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -627,7 +627,7 @@ _cairo_image_surface_set_matrix (cairo_i
     return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_status_t
+static void
 _cairo_image_surface_set_filter (cairo_image_surface_t *surface, cairo_filter_t filter)
 {
     pixman_filter_t pixman_filter;
@@ -659,11 +659,9 @@ _cairo_image_surface_set_filter (cairo_i
     }
 
     pixman_image_set_filter (surface->pixman_image, pixman_filter, NULL, 0);
-
-    return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_int_status_t
+static cairo_status_t
 _cairo_image_surface_set_attributes (cairo_image_surface_t      *surface,
 				     cairo_surface_attributes_t *attributes)
 {
@@ -688,9 +686,9 @@ _cairo_image_surface_set_attributes (cai
 	break;
     }
 
-    status = _cairo_image_surface_set_filter (surface, attributes->filter);
+    _cairo_image_surface_set_filter (surface, attributes->filter);
 
-    return status;
+    return CAIRO_STATUS_SUCCESS;
 }
 
 /* XXX: I think we should fix pixman to match the names/order of the
@@ -1074,8 +1072,7 @@ _cairo_image_surface_reset (void *abstra
     cairo_status_t status;
 
     status = _cairo_image_surface_set_clip_region (surface, NULL);
-    if (status)
-	return status;
+    assert (status == CAIRO_STATUS_SUCCESS);
 
     return CAIRO_STATUS_SUCCESS;
 }
diff-tree 4e39e30d83fc1866a44f0b746c406ee2efb3bf6a (from b72b06cc222d88015ce78a5cddf061e903d032b5)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Jul 16 09:25:38 2007 +0100

    [cairo-pen] Remove status from _cairo_pen_find_active_vertex_*()
    
    This pair of functions unconditionally return SUCCESS, so remove the
    status return and supporting tests from their callers.

diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c
index d9f7ed2..d8d989b 100644
--- a/src/cairo-path-stroke.c
+++ b/src/cairo-path-stroke.c
@@ -237,21 +237,13 @@ _cairo_stroker_join (cairo_stroker_t *st
 
 	tri[0] = in->point;
 	if (clockwise) {
-	    status = _cairo_pen_find_active_ccw_vertex_index (pen, &in->dev_vector, &start);
-	    if (status)
-		return status;
+	    _cairo_pen_find_active_ccw_vertex_index (pen, &in->dev_vector, &start);
 	    step = -1;
-	    status = _cairo_pen_find_active_ccw_vertex_index (pen, &out->dev_vector, &stop);
-	    if (status)
-		return status;
+	    _cairo_pen_find_active_ccw_vertex_index (pen, &out->dev_vector, &stop);
 	} else {
-	    status = _cairo_pen_find_active_cw_vertex_index (pen, &in->dev_vector, &start);
-	    if (status)
-		return status;
+	    _cairo_pen_find_active_cw_vertex_index (pen, &in->dev_vector, &start);
 	    step = +1;
-	    status = _cairo_pen_find_active_cw_vertex_index (pen, &out->dev_vector, &stop);
-	    if (status)
-		return status;
+	    _cairo_pen_find_active_cw_vertex_index (pen, &out->dev_vector, &stop);
 	}
 
 	i = start;
@@ -394,14 +386,10 @@ _cairo_stroker_add_cap (cairo_stroker_t 
 	cairo_pen_t *pen = &stroker->pen;
 
 	slope = f->dev_vector;
-	status = _cairo_pen_find_active_cw_vertex_index (pen, &slope, &start);
-	if (status)
-	    return status;
+	_cairo_pen_find_active_cw_vertex_index (pen, &slope, &start);
 	slope.dx = -slope.dx;
 	slope.dy = -slope.dy;
-	status = _cairo_pen_find_active_cw_vertex_index (pen, &slope, &stop);
-	if (status)
-	    return status;
+	_cairo_pen_find_active_cw_vertex_index (pen, &slope, &stop);
 
 	tri[0] = f->point;
 	tri[1] = f->cw;
diff --git a/src/cairo-pen.c b/src/cairo-pen.c
index 9960f0e..0ff01f3 100644
--- a/src/cairo-pen.c
+++ b/src/cairo-pen.c
@@ -308,7 +308,7 @@ _cairo_pen_compute_slopes (cairo_pen_t *
  * counterclockwise order. However, for this function, we care
  * strongly about which vertex is returned.
  */
-cairo_status_t
+void
 _cairo_pen_find_active_cw_vertex_index (cairo_pen_t *pen,
 					cairo_slope_t *slope,
 					int *active)
@@ -324,8 +324,6 @@ _cairo_pen_find_active_cw_vertex_index (
     assert (i < pen->num_vertices);
 
     *active = i;
-
-    return CAIRO_STATUS_SUCCESS;
 }
 
 /* Find active pen vertex for counterclockwise edge of stroke at the given slope.
@@ -333,7 +331,7 @@ _cairo_pen_find_active_cw_vertex_index (
  * NOTE: The behavior of this function is sensitive to the sense of
  * the inequality within _cairo_slope_clockwise/_cairo_slope_counter_clockwise.
  */
-cairo_status_t
+void
 _cairo_pen_find_active_ccw_vertex_index (cairo_pen_t *pen,
 					 cairo_slope_t *slope,
 					 int *active)
@@ -352,8 +350,6 @@ _cairo_pen_find_active_ccw_vertex_index 
     }
 
     *active = i;
-
-    return CAIRO_STATUS_SUCCESS;
 }
 
 static void
@@ -388,11 +384,9 @@ _cairo_pen_stroke_spline_half (cairo_pen
 	final_slope.dy = -final_slope.dy;
     }
 
-    status = _cairo_pen_find_active_cw_vertex_index (pen,
-	                                             &initial_slope,
-						     &active);
-    if (status)
-	return status;
+    _cairo_pen_find_active_cw_vertex_index (pen,
+	                                    &initial_slope,
+					    &active);
 
     i = start;
     while (i != stop) {
diff --git a/src/cairoint.h b/src/cairoint.h
index 788537f..dca8e6a 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -2112,12 +2112,12 @@ _cairo_pen_add_points_for_slopes (cairo_
 				  cairo_point_t *c,
 				  cairo_point_t *d);
 
-cairo_private cairo_status_t
+cairo_private void
 _cairo_pen_find_active_cw_vertex_index (cairo_pen_t *pen,
 					cairo_slope_t *slope,
 					int *active);
 
-cairo_private cairo_status_t
+cairo_private void
 _cairo_pen_find_active_ccw_vertex_index (cairo_pen_t *pen,
 					 cairo_slope_t *slope,
 					 int *active);
diff-tree b72b06cc222d88015ce78a5cddf061e903d032b5 (from e24969a94ac5670a13c2737db435ac7b5bebb19c)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Jul 16 09:40:47 2007 +0100

    [cairo-pen] Remove hard-coded CAIRO_STATUS_SUCCESS from _stroke_spline_half()
    
    Remove the status return and update callers as
    _cairo_pen_stroke_spline_half() unconditionally returned SUCCESS.

diff --git a/src/cairo-pen.c b/src/cairo-pen.c
index 9392322..9960f0e 100644
--- a/src/cairo-pen.c
+++ b/src/cairo-pen.c
@@ -42,7 +42,7 @@ _cairo_pen_vertices_needed (double toler
 static void
 _cairo_pen_compute_slopes (cairo_pen_t *pen);
 
-static cairo_status_t
+static void
 _cairo_pen_stroke_spline_half (cairo_pen_t *pen, cairo_spline_t *spline, cairo_direction_t dir, cairo_polygon_t *polygon);
 
 void
@@ -356,14 +356,13 @@ _cairo_pen_find_active_ccw_vertex_index 
     return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_status_t
+static void
 _cairo_pen_stroke_spline_half (cairo_pen_t *pen,
 			       cairo_spline_t *spline,
 			       cairo_direction_t dir,
 			       cairo_polygon_t *polygon)
 {
     int i;
-    cairo_status_t status;
     int start, stop, step;
     int active = 0;
     cairo_point_t hull_point;
@@ -416,8 +415,6 @@ _cairo_pen_stroke_spline_half (cairo_pen
 	    i += step;
 	}
     }
-
-    return CAIRO_STATUS_SUCCESS;
 }
 
 /* Compute outline of a given spline using the pen.
@@ -443,13 +440,9 @@ _cairo_pen_stroke_spline (cairo_pen_t		*
     if (status)
 	goto BAIL;
 
-    status = _cairo_pen_stroke_spline_half (pen, spline, CAIRO_DIRECTION_FORWARD, &polygon);
-    if (status)
-	goto BAIL;
+    _cairo_pen_stroke_spline_half (pen, spline, CAIRO_DIRECTION_FORWARD, &polygon);
 
-    status = _cairo_pen_stroke_spline_half (pen, spline, CAIRO_DIRECTION_REVERSE, &polygon);
-    if (status)
-	goto BAIL;
+    _cairo_pen_stroke_spline_half (pen, spline, CAIRO_DIRECTION_REVERSE, &polygon);
 
     _cairo_polygon_close (&polygon);
     status = _cairo_polygon_status (&polygon);
diff-tree e24969a94ac5670a13c2737db435ac7b5bebb19c (from 50ebdda3a97334e5411749cd0c309843ba8cdf44)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Jul 16 09:36:54 2007 +0100

    [cairo-pdf-surface] cairo_pattern_set_matrix guarantees invertibility.
    
    Be consistent in asserting that the pattern matrix is inverted
    successfully and remove a couple of redundant checks.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index e29f3b8..55279a6 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -1439,8 +1439,8 @@ _cairo_pdf_surface_emit_linear_pattern (
 
     pat_to_pdf = pattern->base.base.matrix;
     status = cairo_matrix_invert (&pat_to_pdf);
-    if (status)
-	return status;
+    /* cairo_pattern_set_matrix ensures the matrix is invertible */
+    assert (status == CAIRO_STATUS_SUCCESS);
 
     cairo_matrix_multiply (&pat_to_pdf, &pat_to_pdf, &surface->cairo_to_pdf);
     x1 = _cairo_fixed_to_double (pattern->p1.x);
@@ -1561,8 +1561,8 @@ _cairo_pdf_surface_emit_radial_pattern (
 
     pat_to_pdf = pattern->base.base.matrix;
     status = cairo_matrix_invert (&pat_to_pdf);
-    if (status)
-	return status;
+    /* cairo_pattern_set_matrix ensures the matrix is invertible */
+    assert (status == CAIRO_STATUS_SUCCESS);
 
     cairo_matrix_multiply (&pat_to_pdf, &pat_to_pdf, &surface->cairo_to_pdf);
     x1 = _cairo_fixed_to_double (pattern->c1.x);
diff-tree 50ebdda3a97334e5411749cd0c309843ba8cdf44 (from 7d853bcabcc1c55b79a05280a0eb35828b93163d)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jul 19 10:26:37 2007 +0100

    [cairo-pattern] Assert that the pattern->matrix is invertible.
    
    We guarantee when setting the pattern->matrix that it is invertible, so
    merely assert that it is so when we attempt to use its inverse.

diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 2fd1c87..43c9dc4 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -1979,8 +1979,8 @@ _cairo_pattern_get_extents (cairo_patter
 
 	imatrix = pattern->matrix;
 	status = cairo_matrix_invert (&imatrix);
-	if (status)
-	    return status;
+	/* cairo_pattern_set_matrix ensures the matrix is invertible */
+	assert (status == CAIRO_STATUS_SUCCESS);
 
 	/* XXX Use _cairo_matrix_transform_bounding_box here */
 	for (sy = 0; sy <= 1; sy++) {
diff-tree 7d853bcabcc1c55b79a05280a0eb35828b93163d (from bc635da45a32eb9b7aff6fa5f7f560ebf99092a8)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Aug 16 14:34:07 2007 +0100

    [cairo-boilerplate-xlib] Check for NULL xrender_format before use.
    
    Testing for XRender support (xrender_format != NULL) after
    dereferencing said format doesn't work as intended.

diff --git a/boilerplate/cairo-boilerplate-xlib.c b/boilerplate/cairo-boilerplate-xlib.c
index 615fc98..bfdc7d0 100644
--- a/boilerplate/cairo-boilerplate-xlib.c
+++ b/boilerplate/cairo-boilerplate-xlib.c
@@ -124,13 +124,24 @@ _cairo_boilerplate_xlib_perf_create_surf
     switch (content) {
     case CAIRO_CONTENT_COLOR_ALPHA:
 	xrender_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
+	if (xrender_format == NULL) {
+	    CAIRO_BOILERPLATE_LOG ("X server does not have the Render extension.\n");
+	    return NULL;
+	}
+
 	xtc->drawable = XCreatePixmap (dpy, DefaultRootWindow (dpy),
 				       width, height, xrender_format->depth);
 	xtc->drawable_is_pixmap = TRUE;
 	break;
+
     case CAIRO_CONTENT_COLOR:
 	visual = DefaultVisual (dpy, DefaultScreen (dpy));
 	xrender_format = XRenderFindVisualFormat (dpy, visual);
+	if (xrender_format == NULL) {
+	    CAIRO_BOILERPLATE_LOG ("X server does not have the Render extension.\n");
+	    return NULL;
+	}
+
 	attr.override_redirect = True;
 	xtc->drawable = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0,
 				       width, height, 0, xrender_format->depth,
@@ -138,15 +149,12 @@ _cairo_boilerplate_xlib_perf_create_surf
 	XMapWindow (dpy, xtc->drawable);
 	xtc->drawable_is_pixmap = FALSE;
 	break;
+
     case CAIRO_CONTENT_ALPHA:
     default:
 	CAIRO_BOILERPLATE_LOG ("Invalid content for xlib test: %d\n", content);
 	return NULL;
     }
-    if (xrender_format == NULL) {
-	CAIRO_BOILERPLATE_LOG ("X server does not have the Render extension.\n");
-	return NULL;
-    }
 
     return cairo_xlib_surface_create_with_xrender_format (dpy, xtc->drawable,
 							  DefaultScreenOfDisplay (dpy),


More information about the cairo-commit mailing list