[cairo] [PATCH 5/5] fallback: Silence gcc warning

Andrea Canciani ranma42 at gmail.com
Sat Mar 19 04:27:02 PDT 2011


On Fri, Mar 18, 2011 at 11:42 PM, Andrea Canciani <ranma42 at gmail.com> wrote:
> On Fri, Mar 18, 2011 at 10:35 PM, Behdad Esfahbod <behdad at behdad.org> wrote:
>> On 03/18/11 18:26, Andrea Canciani wrote:
>>> He suggests a behavior, but does not provide a solution.

I realized that mi first mail sounded much more harsh than I meant.
Sorry for that.

>>
>> Just mark the function cairo_private_no_warn instead of cairo_private.  At
>> some point we decided that we prefer to default to warn instead of no_warn, so
>> that's what cairo_private expands to, which is unintuitive to say the least.
>
> This definitely looks like what I should have done!
> In fact I'm now also trying to cleanup the "useless" variables
> sprinkled through the code.
>
> Thank you for pointing out this attribute!

The attachment is a new patch which fixes the same warning and also cleans
up the places where we were using the temp variable trick to silence gcc.

Andrea
-------------- next part --------------
From ab8c108b88edf49959b95a8d7cc12edb239d361c Mon Sep 17 00:00:00 2001
From: Andrea Canciani <ranma42 at gmail.com>
Date: Fri, 18 Mar 2011 16:57:04 +0100
Subject: [PATCH 5/5] Do not warn when ignoring the return value of _cairo_rectangle_intersect()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

gcc complains that

cairo-surface-wrapper.c:647: warning: ignoring return value of
?_cairo_rectangle_intersect?, declared with attribute warn_unused_result

It can be silenced by making _cairo_rectangle_intersect()
cairo_private_no_warn. This makes it possible to avoid unused
temporary variables in other places and reduces the dead assignments
reported by clang static analyzer from 114 to 98.
---
 src/cairo-analysis-surface.c    |   21 +++++++--------------
 src/cairo-clip.c                |   10 ++++------
 src/cairo-gstate.c              |    4 +---
 src/cairo-pattern.c             |    7 +------
 src/cairo-pdf-surface.c         |    8 ++------
 src/cairo.c                     |    2 +-
 src/cairoint.h                  |    2 +-
 src/drm/cairo-drm-i915-shader.c |    8 ++------
 8 files changed, 19 insertions(+), 43 deletions(-)

diff --git a/src/cairo-analysis-surface.c b/src/cairo-analysis-surface.c
index 6bec205..5468eac 100644
--- a/src/cairo-analysis-surface.c
+++ b/src/cairo-analysis-surface.c
@@ -272,14 +272,13 @@ static void
 _rectangle_intersect_clip (cairo_rectangle_int_t *extents, cairo_clip_t *clip)
 {
     const cairo_rectangle_int_t *clip_extents;
-    cairo_bool_t is_empty;
 
     clip_extents = NULL;
     if (clip != NULL)
 	clip_extents = _cairo_clip_get_extents (clip);
 
     if (clip_extents != NULL)
-	is_empty = _cairo_rectangle_intersect (extents, clip_extents);
+	_cairo_rectangle_intersect (extents, clip_extents);
 }
 
 static void
@@ -297,7 +296,7 @@ _cairo_analysis_surface_operation_extents (cairo_analysis_surface_t *surface,
 	cairo_rectangle_int_t source_extents;
 
 	_cairo_pattern_get_extents (source, &source_extents);
-	is_empty = _cairo_rectangle_intersect (extents, &source_extents);
+	_cairo_rectangle_intersect (extents, &source_extents);
     }
 
     _rectangle_intersect_clip (extents, clip);
@@ -343,7 +342,6 @@ _cairo_analysis_surface_mask (void			*abstract_surface,
     cairo_analysis_surface_t *surface = abstract_surface;
     cairo_int_status_t	      backend_status;
     cairo_rectangle_int_t   extents;
-    cairo_bool_t is_empty;
 
     if (surface->target->backend->mask == NULL) {
 	backend_status = CAIRO_INT_STATUS_UNSUPPORTED;
@@ -392,8 +390,7 @@ _cairo_analysis_surface_mask (void			*abstract_surface,
 	cairo_rectangle_int_t mask_extents;
 
 	_cairo_pattern_get_extents (mask, &mask_extents);
-	is_empty = _cairo_rectangle_intersect (&extents, &mask_extents);
-
+	_cairo_rectangle_intersect (&extents, &mask_extents);
     }
 
     return _add_operation (surface, &extents, backend_status);
@@ -414,7 +411,6 @@ _cairo_analysis_surface_stroke (void			*abstract_surface,
     cairo_analysis_surface_t *surface = abstract_surface;
     cairo_status_t	     backend_status;
     cairo_rectangle_int_t    extents;
-    cairo_bool_t             is_empty;
 
     if (surface->target->backend->stroke == NULL) {
 	backend_status = CAIRO_INT_STATUS_UNSUPPORTED;
@@ -447,7 +443,7 @@ _cairo_analysis_surface_stroke (void			*abstract_surface,
 	if (unlikely (status))
 	    return status;
 
-	is_empty = _cairo_rectangle_intersect (&extents, &mask_extents);
+	_cairo_rectangle_intersect (&extents, &mask_extents);
     }
 
     return _add_operation (surface, &extents, backend_status);
@@ -466,7 +462,6 @@ _cairo_analysis_surface_fill (void			*abstract_surface,
     cairo_analysis_surface_t *surface = abstract_surface;
     cairo_status_t	     backend_status;
     cairo_rectangle_int_t    extents;
-    cairo_bool_t             is_empty;
 
     if (surface->target->backend->fill == NULL) {
 	backend_status = CAIRO_INT_STATUS_UNSUPPORTED;
@@ -493,7 +488,7 @@ _cairo_analysis_surface_fill (void			*abstract_surface,
 	_cairo_path_fixed_fill_extents (path, fill_rule, tolerance,
 					&mask_extents);
 
-	is_empty = _cairo_rectangle_intersect (&extents, &mask_extents);
+	_cairo_rectangle_intersect (&extents, &mask_extents);
     }
 
     return _add_operation (surface, &extents, backend_status);
@@ -512,7 +507,6 @@ _cairo_analysis_surface_show_glyphs (void		  *abstract_surface,
     cairo_analysis_surface_t *surface = abstract_surface;
     cairo_status_t	     status, backend_status;
     cairo_rectangle_int_t    extents, glyph_extents;
-    cairo_bool_t             is_empty;
 
     /* Adapted from _cairo_surface_show_glyphs */
     if (surface->target->backend->show_glyphs != NULL) {
@@ -561,7 +555,7 @@ _cairo_analysis_surface_show_glyphs (void		  *abstract_surface,
 	if (unlikely (status))
 	    return status;
 
-	is_empty = _cairo_rectangle_intersect (&extents, &glyph_extents);
+	_cairo_rectangle_intersect (&extents, &glyph_extents);
     }
 
     return _add_operation (surface, &extents, backend_status);
@@ -592,7 +586,6 @@ _cairo_analysis_surface_show_text_glyphs (void			    *abstract_surface,
     cairo_analysis_surface_t *surface = abstract_surface;
     cairo_status_t	     status, backend_status;
     cairo_rectangle_int_t    extents, glyph_extents;
-    cairo_bool_t             is_empty;
 
     /* Adapted from _cairo_surface_show_glyphs */
     backend_status = CAIRO_INT_STATUS_UNSUPPORTED;
@@ -645,7 +638,7 @@ _cairo_analysis_surface_show_text_glyphs (void			    *abstract_surface,
 	if (unlikely (status))
 	    return status;
 
-	is_empty = _cairo_rectangle_intersect (&extents, &glyph_extents);
+	_cairo_rectangle_intersect (&extents, &glyph_extents);
     }
 
     return _add_operation (surface, &extents, backend_status);
diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index c76beee..a695cd7 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -368,7 +368,6 @@ _cairo_clip_path_reapply_clip_path_transform (cairo_clip_t      *clip,
 {
     cairo_status_t status;
     cairo_clip_path_t *clip_path;
-    cairo_bool_t is_empty;
 
     if (other_path->prev != NULL) {
         status = _cairo_clip_path_reapply_clip_path_transform (clip,
@@ -394,8 +393,8 @@ _cairo_clip_path_reapply_clip_path_transform (cairo_clip_t      *clip,
     _cairo_path_fixed_approximate_clip_extents (&clip_path->path,
 						&clip_path->extents);
     if (clip_path->prev != NULL) {
-	is_empty = _cairo_rectangle_intersect (&clip_path->extents,
-					       &clip_path->prev->extents);
+	_cairo_rectangle_intersect (&clip_path->extents,
+				    &clip_path->prev->extents);
     }
 
     clip_path->fill_rule = other_path->fill_rule;
@@ -1399,7 +1398,6 @@ intersect_with_boxes (cairo_composite_rectangles_t *extents,
 {
     cairo_rectangle_int_t rect;
     cairo_box_t box;
-    cairo_bool_t is_empty;
 
     box.p1.x = box.p1.y = INT_MIN;
     box.p2.x = box.p2.y = INT_MAX;
@@ -1416,8 +1414,8 @@ intersect_with_boxes (cairo_composite_rectangles_t *extents,
     }
 
     _cairo_box_round_to_rectangle (&box, &rect);
-    is_empty = _cairo_rectangle_intersect (&extents->bounded, &rect);
-    is_empty = _cairo_rectangle_intersect (&extents->unbounded, &rect);
+    _cairo_rectangle_intersect (&extents->bounded, &rect);
+    _cairo_rectangle_intersect (&extents->unbounded, &rect);
 }
 
 cairo_status_t
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 9fd3600..ac73ca9 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -1511,9 +1511,7 @@ _cairo_gstate_int_clip_extents (cairo_gstate_t        *gstate,
 
     clip_extents = _cairo_clip_get_extents (&gstate->clip);
     if (clip_extents != NULL) {
-	cairo_bool_t is_empty;
-
-	is_empty = _cairo_rectangle_intersect (extents, clip_extents);
+	_cairo_rectangle_intersect (extents, clip_extents);
 	is_bounded = TRUE;
     }
 
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 5663a9b..8531aa5 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -3782,7 +3782,6 @@ _cairo_pattern_acquire_surface_for_surface (const cairo_surface_pattern_t   *pat
     int tx, ty;
     double pad;
     cairo_bool_t is_identity;
-    cairo_bool_t is_empty;
     cairo_bool_t is_bounded;
     cairo_int_status_t status;
 
@@ -3953,7 +3952,7 @@ _cairo_pattern_acquire_surface_for_surface (const cairo_surface_pattern_t   *pat
     if ( _cairo_surface_get_extents (surface, &extents)) {
 	if (attr->extend == CAIRO_EXTEND_NONE) {
 	    /* Never acquire a larger area than the source itself */
-	    is_empty = _cairo_rectangle_intersect (&extents, &sampled_area);
+	    _cairo_rectangle_intersect (&extents, &sampled_area);
 	} else {
 	    int trim = 0;
 
@@ -3979,13 +3978,9 @@ _cairo_pattern_acquire_surface_for_surface (const cairo_surface_pattern_t   *pat
 		/* source is wholly contained within extents, drop the REPEAT */
 		attr->extend = CAIRO_EXTEND_NONE;
 	    }
-
-	    is_empty = extents.width == 0 || extents.height == 0;
 	}
     }
 
-    /* XXX can we use is_empty? */
-
     status = _cairo_surface_clone_similar (dst, surface,
 					   extents.x, extents.y,
 					   extents.width, extents.height,
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index c915b3f..b4b2981 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -6309,14 +6309,12 @@ _cairo_pdf_surface_fill_stroke (void			*abstract_surface,
 
     /* use the more accurate extents */
     if (extents.is_bounded) {
-	cairo_bool_t is_empty;
-
 	_cairo_path_fixed_fill_extents (path,
 					fill_rule,
 					fill_tolerance,
 					&extents.mask);
 
-	is_empty = ! _cairo_rectangle_intersect (&extents.bounded, &extents.mask);
+	_cairo_rectangle_intersect (&extents.bounded, &extents.mask);
     }
 
     fill_pattern_res.id = 0;
@@ -6343,8 +6341,6 @@ _cairo_pdf_surface_fill_stroke (void			*abstract_surface,
 
     /* use the more accurate extents */
     if (extents.is_bounded) {
-	cairo_bool_t is_empty;
-
 	status = _cairo_path_fixed_stroke_extents (path, stroke_style,
 						   stroke_ctm, stroke_ctm_inverse,
 						   stroke_tolerance,
@@ -6352,7 +6348,7 @@ _cairo_pdf_surface_fill_stroke (void			*abstract_surface,
 	if (unlikely (status))
 	    return status;
 
-	is_empty = ! _cairo_rectangle_intersect (&extents.bounded, &extents.mask);
+	_cairo_rectangle_intersect (&extents.bounded, &extents.mask);
     }
 
     stroke_pattern_res.id = 0;
diff --git a/src/cairo.c b/src/cairo.c
index 5969fe5..e1a8e91 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -694,7 +694,7 @@ cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
 	is_empty = _cairo_surface_get_extents (parent_surface, &extents);
 	clip_extents = _cairo_clip_get_extents (_cairo_gstate_get_clip (cr->gstate));
 	if (clip_extents != NULL)
-	    is_empty = _cairo_rectangle_intersect (&extents, clip_extents);
+	    _cairo_rectangle_intersect (&extents, clip_extents);
 
 	group_surface = _cairo_surface_create_similar_solid (parent_surface,
 							     content,
diff --git a/src/cairoint.h b/src/cairoint.h
index 0bfea8f..afd7de2 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -283,7 +283,7 @@ _cairo_unbounded_rectangle_init (cairo_rectangle_int_t *rect)
     rect->height = CAIRO_RECT_INT_MAX - CAIRO_RECT_INT_MIN;
 }
 
-cairo_private cairo_bool_t
+cairo_private_no_warn cairo_bool_t
 _cairo_rectangle_intersect (cairo_rectangle_int_t *dst,
 			    const cairo_rectangle_int_t *src);
 
diff --git a/src/drm/cairo-drm-i915-shader.c b/src/drm/cairo-drm-i915-shader.c
index 84e501f..b67608a 100644
--- a/src/drm/cairo-drm-i915-shader.c
+++ b/src/drm/cairo-drm-i915-shader.c
@@ -1502,12 +1502,8 @@ sampled_area (const cairo_surface_pattern_t *pattern,
     sample->width  = ceil (x2 + pad) - sample->x;
     sample->height = ceil (y2 + pad) - sample->y;
 
-    if (_cairo_surface_get_extents (pattern->surface, &surface_extents)) {
-	cairo_bool_t is_empty;
-
-	is_empty = _cairo_rectangle_intersect (sample,
-					       &surface_extents);
-    }
+    if (_cairo_surface_get_extents (pattern->surface, &surface_extents))
+	_cairo_rectangle_intersect (sample, &surface_extents);
 
     return filter;
 }
-- 
1.7.1


More information about the cairo mailing list