[cairo] Add attribute(warn_unused_result)

Chris Wilson chris at chris-wilson.co.uk
Wed Mar 28 10:20:42 PDT 2007


Another batch of missing error checks and similar mistakes.
--
Chris Wilson
-------------- next part --------------
>From a4726471c905b73f065520e6fb4892f86e72264a Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed, 28 Mar 2007 16:54:03 +0100
Subject: [PATCH] Populate cairo-bentley-ottmann.c with cairo_static forward declarations.

This caught an instance where an error status was not checked.
---
 src/cairo-bentley-ottmann.c |  161 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 152 insertions(+), 9 deletions(-)

diff --git a/src/cairo-bentley-ottmann.c b/src/cairo-bentley-ottmann.c
index 14308f8..6459166 100644
--- a/src/cairo-bentley-ottmann.c
+++ b/src/cairo-bentley-ottmann.c
@@ -138,17 +138,158 @@ typedef struct _cairo_bo_sweep_line {
 } cairo_bo_sweep_line_t;
 
 
-cairo_static cairo_status_t
-_cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t	*sweep_line,
-			     cairo_bo_edge_t		*edge);
+cairo_static cairo_quorem64_t
+edge_x_for_y (cairo_bo_edge_t *edge,
+	      int32_t y);
+
+cairo_static int
+_cairo_bo_sweep_line_compare_edges (cairo_bo_sweep_line_t	*sweep_line,
+				    cairo_bo_edge_t		*a,
+				    cairo_bo_edge_t		*b);
+
+cairo_static int
+_sweep_line_elt_compare (void	*list,
+			 void	*a,
+			 void	*b);
+
+cairo_static inline int
+cairo_bo_event_compare (cairo_bo_event_t const *a,
+			cairo_bo_event_t const *b);
+
+cairo_static int
+cairo_bo_event_compare_abstract (void		*list,
+				 void	*a,
+				 void	*b);
+
+cairo_static int
+cairo_bo_event_compare_pointers (void const *voida,
+				 void const *voidb);
+
+cairo_static inline cairo_int64_t
+det32_64 (int32_t a,
+	  int32_t b,
+	  int32_t c,
+	  int32_t d);
+
+cairo_static inline cairo_int128_t
+det64_128 (cairo_int64_t a,
+	   cairo_int64_t b,
+	   cairo_int64_t c,
+	   cairo_int64_t d);
+
+cairo_static cairo_bo_status_t
+intersect_lines (cairo_bo_edge_t		*a,
+		 cairo_bo_edge_t		*b,
+		 cairo_bo_intersect_point_t	*intersection);
+
+cairo_static int
+_cairo_bo_intersect_ordinate_32_compare (cairo_bo_intersect_ordinate_t	a,
+					 int32_t			b);
+
+cairo_static cairo_bool_t
+_cairo_bo_edge_contains_intersect_point (cairo_bo_edge_t		*edge,
+					 cairo_bo_intersect_point_t	*point);
+
+cairo_static cairo_bo_status_t
+_cairo_bo_edge_intersect (cairo_bo_edge_t	*a,
+			  cairo_bo_edge_t	*b,
+			  cairo_bo_point32_t	*intersection);
+
+cairo_static void
+_cairo_bo_event_init (cairo_bo_event_t		*event,
+		      cairo_bo_event_type_t	 type,
+		      cairo_bo_edge_t	*e1,
+		      cairo_bo_edge_t	*e2,
+		      cairo_bo_point32_t	 point);
+
 cairo_static cairo_status_t
 _cairo_bo_event_queue_insert (cairo_bo_event_queue_t *queue,
 			      cairo_bo_event_t	     *event);
+
+cairo_static void
+_cairo_bo_event_queue_delete (cairo_bo_event_queue_t *queue,
+			      cairo_bo_event_t	     *event);
+
+cairo_static cairo_bo_event_t *
+_cairo_bo_event_dequeue (cairo_bo_event_queue_t *event_queue);
+
+cairo_static cairo_status_t
+_cairo_bo_event_queue_init (cairo_bo_event_queue_t	*event_queue,
+			    cairo_bo_edge_t	        *edges,
+			    int				 num_edges);
+
+cairo_static void
+_cairo_bo_event_queue_fini (cairo_bo_event_queue_t *event_queue);
+
 cairo_static cairo_status_t
 _cairo_bo_event_queue_insert_if_intersect_below_current_y (cairo_bo_event_queue_t	*event_queue,
 							   cairo_bo_edge_t	*left,
 							   cairo_bo_edge_t	*right);
 
+cairo_static void
+_cairo_bo_sweep_line_init (cairo_bo_sweep_line_t *sweep_line);
+
+cairo_static void
+_cairo_bo_sweep_line_fini (cairo_bo_sweep_line_t *sweep_line);
+
+cairo_static cairo_status_t
+_cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t	*sweep_line,
+			     cairo_bo_edge_t		*edge);
+
+cairo_static void
+_cairo_bo_sweep_line_delete (cairo_bo_sweep_line_t	*sweep_line,
+			     cairo_bo_edge_t	        *edge);
+
+cairo_static void
+_cairo_bo_sweep_line_swap (cairo_bo_sweep_line_t	*sweep_line,
+			   cairo_bo_edge_t		*left,
+			   cairo_bo_edge_t		*right);
+cairo_static cairo_status_t
+_cairo_bo_edge_end_trap (cairo_bo_edge_t	*left,
+			 int32_t		 bot,
+			 cairo_bo_traps_t	*bo_traps);
+
+cairo_static cairo_status_t
+_cairo_bo_edge_start_or_continue_trap (cairo_bo_edge_t	*edge,
+				       int32_t		 top,
+				       cairo_bo_traps_t	*bo_traps);
+
+cairo_static void
+_cairo_bo_traps_init (cairo_bo_traps_t	*bo_traps,
+		      cairo_traps_t	*traps,
+		      cairo_fixed_t	 xmin,
+		      cairo_fixed_t	 ymin,
+		      cairo_fixed_t	 xmax,
+		      cairo_fixed_t	 ymax);
+
+cairo_static void
+_cairo_bo_traps_fini (cairo_bo_traps_t *bo_traps);
+
+cairo_static void
+_cairo_bo_sweep_line_validate (cairo_bo_sweep_line_t *sweep_line);
+
+cairo_static cairo_status_t
+_active_edges_to_traps (cairo_bo_edge_t		*head,
+			int32_t			 top,
+			cairo_fill_rule_t	 fill_rule,
+			cairo_bo_traps_t	*bo_traps);
+
+cairo_static cairo_status_t
+_cairo_bentley_ottmann_tessellate_bo_edges (cairo_bo_edge_t	*edges,
+					    int			 num_edges,
+					    cairo_fill_rule_t	 fill_rule,
+					    cairo_traps_t	*traps,
+					    cairo_fixed_t	xmin,
+					    cairo_fixed_t	ymin,
+					    cairo_fixed_t	xmax,
+					    cairo_fixed_t	ymax,
+					    int			*num_intersections);
+
+cairo_static void
+update_minmax(cairo_fixed_t *inout_min,
+	      cairo_fixed_t *inout_max,
+	      cairo_fixed_t v);
+
 static inline int
 _cairo_bo_point32_compare (cairo_bo_point32_t const *a,
 			   cairo_bo_point32_t const *b)
@@ -746,7 +887,7 @@ _cairo_bo_event_dequeue (cairo_bo_event_queue_t *event_queue)
 
 static cairo_status_t
 _cairo_bo_event_queue_init (cairo_bo_event_queue_t	*event_queue,
-			    cairo_bo_edge_t	*edges,
+			    cairo_bo_edge_t	        *edges,
 			    int				 num_edges)
 {
     int i;
@@ -899,7 +1040,7 @@ _cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t	*sweep_line,
 
 static void
 _cairo_bo_sweep_line_delete (cairo_bo_sweep_line_t	*sweep_line,
-			     cairo_bo_edge_t	*edge)
+			     cairo_bo_edge_t	        *edge)
 {
     cairo_bo_edge_t **left_next, **right_prev;
 
@@ -1072,7 +1213,7 @@ print_state (const char			*msg,
  * of bo_traps. */
 static cairo_status_t
 _cairo_bo_edge_end_trap (cairo_bo_edge_t	*left,
-			 int32_t		bot,
+			 int32_t		 bot,
 			 cairo_bo_traps_t	*bo_traps)
 {
     cairo_fixed_t fixed_top, fixed_bot;
@@ -1146,7 +1287,7 @@ _cairo_bo_edge_end_trap (cairo_bo_edge_t	*left,
  * trapezoid would be a continuation of the existing one. */
 static cairo_status_t
 _cairo_bo_edge_start_or_continue_trap (cairo_bo_edge_t	*edge,
-				       int32_t		top,
+				       int32_t		 top,
 				       cairo_bo_traps_t	*bo_traps)
 {
     cairo_status_t status;
@@ -1273,7 +1414,7 @@ _cairo_bentley_ottmann_tessellate_bo_edges (cairo_bo_edge_t	*edges,
 					    cairo_fixed_t	ymax,
 					    int			*num_intersections)
 {
-    cairo_status_t status = CAIRO_STATUS_SUCCESS;
+    cairo_status_t status;
     int intersection_count = 0;
     cairo_bo_event_queue_t event_queue;
     cairo_bo_sweep_line_t sweep_line;
@@ -1283,7 +1424,9 @@ _cairo_bentley_ottmann_tessellate_bo_edges (cairo_bo_edge_t	*edges,
     cairo_bo_edge_t *left, *right;
     cairo_bo_edge_t *edge1, *edge2;
 
-    _cairo_bo_event_queue_init (&event_queue, edges, num_edges);
+    status = _cairo_bo_event_queue_init (&event_queue, edges, num_edges);
+    if (status)
+	return status;
     _cairo_bo_sweep_line_init (&sweep_line);
     _cairo_bo_traps_init (&bo_traps, traps, xmin, ymin, xmax, ymax);
 
-- 
1.4.4.2

-------------- next part --------------
>From 3a87e368ecd8186cd7cb75cf7abddba8906a226c Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed, 28 Mar 2007 17:00:27 +0100
Subject: [PATCH] cairo_skip_list_insert - missing check after malloc.

Return NULL when out of memory and propagate the error status back up
the call chain.
---
 src/cairo-skiplist.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/cairo-skiplist.c b/src/cairo-skiplist.c
index 451ecb0..2374b37 100644
--- a/src/cairo-skiplist.c
+++ b/src/cairo-skiplist.c
@@ -349,6 +349,8 @@ _cairo_skip_list_insert (cairo_skip_list_t *list, void *data, int unique)
     }
 
     data_and_elt = alloc_node_for_level (list, level);
+    if (data_and_elt == NULL)
+	return NULL;
     memcpy (data_and_elt, data, list->data_size);
     elt = (skip_elt_t *) (data_and_elt + list->data_size);
 
-- 
1.4.4.2

-------------- next part --------------
>From b354b03ef697093b40c1679c94a8f7f012cc4b29 Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed, 28 Mar 2007 17:02:35 +0100
Subject: [PATCH] pixman_create_source_image - missing check after malloc

Call chain already checked for a failure that was never reported.
---
 pixman/src/icimage.c    |    2 ++
 src/cairo-scaled-font.c |    1 +
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/pixman/src/icimage.c b/pixman/src/icimage.c
index 62ff209..cd03251 100644
--- a/pixman/src/icimage.c
+++ b/pixman/src/icimage.c
@@ -187,6 +187,8 @@ _pixman_create_source_image (void)
     pixman_image_t *image;
 
     image = (pixman_image_t *) malloc (sizeof (pixman_image_t));
+    if (!image)
+	return NULL;
     image->pDrawable   = NULL;
     image->pixels      = NULL;
     image->format_code = PICT_a8r8g8b8;
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 0b19c8b..35fb692 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -211,6 +211,7 @@ _cairo_scaled_font_map_lock (void)
 
  CLEANUP_SCALED_FONT_MAP:
     free (cairo_scaled_font_map);
+    cairo_scaled_font_map = NULL;
  CLEANUP_MUTEX_LOCK:
     CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex);
     return NULL;
-- 
1.4.4.2

-------------- next part --------------
>From 5dd01e059e26da222419a90f1eab9c3a8c28f67e Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris at chris-wilson.co.uk>
Date: Fri, 16 Mar 2007 19:35:02 +0000
Subject: [PATCH] Handle failure to allocate a GC.

---
 src/cairo-xlib-surface.c |   51 ++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 7f1392d..ff5cdfe 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -51,7 +51,7 @@ typedef int (*cairo_xlib_error_func_t) (Display     *display,
 
 typedef struct _cairo_xlib_surface cairo_xlib_surface_t;
 
-static void
+static cairo_status_t
 _cairo_xlib_surface_ensure_gc (cairo_xlib_surface_t *surface);
 
 static void
@@ -587,22 +587,27 @@ _get_image_surface (cairo_xlib_surface_t    *surface,
 	 * retry, but to keep things simple, we just create a
 	 * temporary pixmap
 	 */
-	Pixmap pixmap = XCreatePixmap (surface->dpy,
+	Pixmap pixmap;
+	cairo_status_t status = _cairo_xlib_surface_ensure_gc (surface);
+	if (status)
+	    return status;
+
+	pixmap = XCreatePixmap (surface->dpy,
 				       surface->drawable,
 				       x2 - x1, y2 - y1,
 				       surface->depth);
-	_cairo_xlib_surface_ensure_gc (surface);
-
-	XCopyArea (surface->dpy, surface->drawable, pixmap, surface->gc,
-		   x1, y1, x2 - x1, y2 - y1, 0, 0);
+	if (pixmap) {
+	    XCopyArea (surface->dpy, surface->drawable, pixmap, surface->gc,
+		       x1, y1, x2 - x1, y2 - y1, 0, 0);
 
-	ximage = XGetImage (surface->dpy,
-			    pixmap,
-			    0, 0,
-			    x2 - x1, y2 - y1,
-			    AllPlanes, ZPixmap);
+	    ximage = XGetImage (surface->dpy,
+				pixmap,
+				0, 0,
+				x2 - x1, y2 - y1,
+				AllPlanes, ZPixmap);
 
-	XFreePixmap (surface->dpy, pixmap);
+	    XFreePixmap (surface->dpy, pixmap);
+	}
     }
     if (!ximage)
 	return CAIRO_STATUS_NO_MEMORY;
@@ -731,18 +736,23 @@ _cairo_xlib_surface_ensure_dst_picture (cairo_xlib_surface_t    *surface)
 
 }
 
-static void
+static cairo_status_t
 _cairo_xlib_surface_ensure_gc (cairo_xlib_surface_t *surface)
 {
     XGCValues gcv;
 
     if (surface->gc)
-	return;
+	return CAIRO_STATUS_SUCCESS;
 
     gcv.graphics_exposures = False;
     surface->gc = XCreateGC (surface->dpy, surface->drawable,
 			     GCGraphicsExposures, &gcv);
+    if (!surface->gc)
+	return CAIRO_STATUS_NO_MEMORY;
+
     _cairo_xlib_surface_set_gc_clip_rects (surface);
+
+    return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_status_t
@@ -758,6 +768,7 @@ _draw_image_surface (cairo_xlib_surface_t   *surface,
     XImage ximage;
     unsigned int bpp, alpha, red, green, blue;
     int native_byte_order = _native_byte_order_lsb () ? LSBFirst : MSBFirst;
+    cairo_status_t status;
 
     pixman_format_get_masks (pixman_image_get_format (image->pixman_image),
 			     &bpp, &alpha, &red, &green, &blue);
@@ -780,7 +791,9 @@ _draw_image_surface (cairo_xlib_surface_t   *surface,
 
     XInitImage (&ximage);
 
-    _cairo_xlib_surface_ensure_gc (surface);
+    status = _cairo_xlib_surface_ensure_gc (surface);
+    if (status)
+	return status;
     XPutImage(surface->dpy, surface->drawable, surface->gc,
 	      &ximage, src_x, src_y, dst_x, dst_y,
 	      width, height);
@@ -1364,7 +1377,9 @@ _cairo_xlib_surface_composite (cairo_operator_t		op,
 	break;
 
     case DO_XCOPYAREA:
-	_cairo_xlib_surface_ensure_gc (dst);
+	status = _cairo_xlib_surface_ensure_gc (dst);
+	if (status)
+	    goto BAIL;
 	XCopyArea (dst->dpy,
 		   src->drawable,
 		   dst->drawable,
@@ -1384,7 +1399,9 @@ _cairo_xlib_surface_composite (cairo_operator_t		op,
 	 * _recategorize_composite_operation.
 	 */
 
-	_cairo_xlib_surface_ensure_gc (dst);
+	status = _cairo_xlib_surface_ensure_gc (dst);
+	if (status)
+	    goto BAIL;
 	_cairo_matrix_is_integer_translation (&src_attr.matrix, &itx, &ity);
 
 	XSetTSOrigin (dst->dpy, dst->gc,
-- 
1.4.4.2

-------------- next part --------------
>From c78d6358eef6c5a9f9cd385ff6328c5e7aa200a5 Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris at chris-wilson.co.uk>
Date: Fri, 16 Mar 2007 20:04:26 +0000
Subject: [PATCH] Avoid using substituted surfaces for xlib operations.

Detect when a substitute image surface is returned for a solid pattern,
and avoid mixed image/xlib composite operations. This can happen for example
if there is a resource allocation failure during creating a similar surface.
---
 src/cairo-xlib-surface.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index ff5cdfe..5914c37 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -1217,7 +1217,12 @@ _recategorize_composite_operation (cairo_xlib_surface_t	      *dst,
 {
     cairo_bool_t is_integer_translation =
 	_cairo_matrix_is_integer_translation (&src_attr->matrix, NULL, NULL);
-    cairo_bool_t needs_alpha_composite =
+    cairo_bool_t needs_alpha_composite;
+
+    if (!_cairo_surface_is_xlib (&src->base))
+	return DO_UNSUPPORTED;
+
+    needs_alpha_composite =
 	_operator_needs_alpha_composite (op, _surface_has_alpha (src));
 
     if (!have_mask &&
-- 
1.4.4.2

-------------- next part --------------
>From b419aa16d10ec913cba0e036191dcbcfab207e45 Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed, 28 Mar 2007 17:58:31 +0100
Subject: [PATCH] Protect boilerplate_xlib_synchronize from alloc failure.

Don't call XDestroyImage on a NULL image.
---
 boilerplate/cairo-boilerplate.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index 858c5c0..cbfb2d4 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -877,7 +877,8 @@ boilerplate_xlib_synchronize (void *closure)
 
     ximage = XGetImage (xtc->dpy, xtc->drawable,
 			0, 0, 1, 1, AllPlanes, ZPixmap);
-    XDestroyImage (ximage);
+    if (ximage != NULL)
+	XDestroyImage (ximage);
 }
 
 /* For the xlib backend we distinguish between TEST and PERF mode in a
-- 
1.4.4.2



More information about the cairo mailing list