[cairo] Fix up the simple warnings
Chris Wilson
chris at chris-wilson.co.uk
Wed Mar 21 09:58:50 PDT 2007
For the majority of warning we can simply propagate the error status.
This leaves some checks that were explicity deferred and others that
appeared more complicated and needed to be dealt with outside of this
mammoth, preferably by people who knew the code better ;-)
-------------- next part --------------
>From fe6572d22374d9309076e5ee7bff7bdfaa30859c Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed, 21 Mar 2007 16:38:43 +0000
Subject: [PATCH] Fix up the simple cases of warn-unused-result.
For the majority of cases of unchecked status returns the most appropiate
action is to propagate the status back up the chain, after performing
all local cleanups. Sometimes this involves changing the prototype to
include the status return and repeating on the process for its callers.
---
boilerplate/cairo-boilerplate.c | 7 ++-
src/cairo-bentley-ottmann.c | 48 +++++++++++-----
src/cairo-clip-private.h | 4 +-
src/cairo-clip.c | 67 ++++++++++++++++------
src/cairo-ft-font.c | 107 +++++++++++++++++++++++++----------
src/cairo-gstate.c | 32 ++++++++--
src/cairo-meta-surface.c | 4 +-
src/cairo-paginated-surface.c | 33 ++++++++---
src/cairo-path-fill.c | 2 +-
src/cairo-path-stroke.c | 119 ++++++++++++++++++++++++++------------
src/cairo-path.c | 50 +++++++++--------
src/cairo-pattern.c | 4 +-
src/cairo-pdf-surface.c | 34 +++++++-----
src/cairo-pen.c | 28 ++++++---
src/cairo-polygon.c | 8 +-
src/cairo-ps-surface.c | 73 +++++++++++++++---------
src/cairo-scaled-font.c | 53 +++++++++++------
src/cairo-surface-fallback.c | 28 ++++++---
src/cairo-svg-surface.c | 47 ++++++++++++----
src/cairo-traps.c | 1 +
src/cairo-truetype-subset.c | 15 ++++-
src/cairo-type1-fallback.c | 28 +++++++---
src/cairo-xlib-private.h | 2 +-
src/cairo.c | 69 +++++++++++++++--------
src/cairoint.h | 10 ++--
test/buffer-diff.c | 6 +-
26 files changed, 595 insertions(+), 284 deletions(-)
diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index f726d42..6ea5e52 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -1095,7 +1095,12 @@ create_ps_surface (const char *name,
ptc->target = NULL;
}
- cairo_surface_set_user_data (surface, &ps_closure_key, ptc, NULL);
+ if (cairo_surface_set_user_data (surface, &ps_closure_key, ptc, NULL)) {
+ cairo_surface_destroy (surface);
+ free (ptc->filename);
+ free (ptc);
+ return NULL;
+ }
return surface;
}
diff --git a/src/cairo-bentley-ottmann.c b/src/cairo-bentley-ottmann.c
index 873bfd6..0248a38 100644
--- a/src/cairo-bentley-ottmann.c
+++ b/src/cairo-bentley-ottmann.c
@@ -692,13 +692,15 @@ _cairo_bo_event_init (cairo_bo_event_t *event,
event->point = point;
}
-static void
+cairo_static cairo_status_t
_cairo_bo_event_queue_insert (cairo_bo_event_queue_t *queue,
cairo_bo_event_t *event)
{
/* Don't insert if there's already an equivalent intersection event in the queue. */
- _cairo_skip_list_insert (&queue->intersection_queue, event,
- event->type == CAIRO_BO_EVENT_TYPE_INTERSECTION);
+ if (_cairo_skip_list_insert (&queue->intersection_queue, event,
+ event->type == CAIRO_BO_EVENT_TYPE_INTERSECTION) == NULL)
+ return CAIRO_STATUS_NO_MEMORY;
+ return CAIRO_STATUS_SUCCESS;
}
static void
@@ -796,7 +798,7 @@ _cairo_bo_event_queue_fini (cairo_bo_event_queue_t *event_queue)
free (event_queue->sorted_startstop_event_ptrs);
}
-static void
+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)
@@ -806,7 +808,7 @@ _cairo_bo_event_queue_insert_if_intersect_below_current_y (cairo_bo_event_queue_
cairo_bo_event_t event;
if (left == NULL || right == NULL)
- return;
+ return CAIRO_STATUS_SUCCESS;
/* The names "left" and "right" here are correct descriptions of
* the order of the two edges within the active edge list. So if a
@@ -814,13 +816,13 @@ _cairo_bo_event_queue_insert_if_intersect_below_current_y (cairo_bo_event_queue_
* that the intersection of these two segments has oalready
* occurred before the current sweep line position. */
if (_slope_compare (left, right) < 0)
- return;
+ return CAIRO_STATUS_SUCCESS;
status = _cairo_bo_edge_intersect (left, right, &intersection);
if (status == CAIRO_BO_STATUS_PARALLEL ||
status == CAIRO_BO_STATUS_NO_INTERSECTION)
{
- return;
+ return CAIRO_STATUS_SUCCESS;
}
_cairo_bo_event_init (&event,
@@ -828,7 +830,7 @@ _cairo_bo_event_queue_insert_if_intersect_below_current_y (cairo_bo_event_queue_
left, right,
intersection);
- _cairo_bo_event_queue_insert (event_queue, &event);
+ return _cairo_bo_event_queue_insert (event_queue, &event);
}
static void
@@ -848,7 +850,7 @@ _cairo_bo_sweep_line_fini (cairo_bo_sweep_line_t *sweep_line)
_cairo_skip_list_fini (&sweep_line->active_edges);
}
-static void
+static cairo_status_t
_cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t *sweep_line,
cairo_bo_edge_t *edge)
{
@@ -858,6 +860,8 @@ _cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t *sweep_line,
sweep_line_elt = _cairo_skip_list_insert (&sweep_line->active_edges, &edge,
1 /* unique inserts*/);
+ if (sweep_line_elt == NULL)
+ return CAIRO_STATUS_NO_MEMORY;
next_elt = sweep_line_elt->elt.next[0];
if (next_elt)
@@ -876,6 +880,8 @@ _cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t *sweep_line,
*next_of_prev = edge;
edge->sweep_line_elt = sweep_line_elt;
+
+ return CAIRO_STATUS_SUCCESS;
}
static void
@@ -1296,7 +1302,9 @@ _cairo_bentley_ottmann_tessellate_bo_edges (cairo_bo_edge_t *edges,
case CAIRO_BO_EVENT_TYPE_START:
edge = event->e1;
- _cairo_bo_sweep_line_insert (&sweep_line, edge);
+ status = _cairo_bo_sweep_line_insert (&sweep_line, edge);
+ if (status)
+ goto unwind;
/* Cache the insert position for use in pass 2.
event->e2 = Sortlist::prev (sweep_line, edge);
*/
@@ -1304,9 +1312,13 @@ _cairo_bentley_ottmann_tessellate_bo_edges (cairo_bo_edge_t *edges,
left = edge->prev;
right = edge->next;
- _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, edge);
+ status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, edge);
+ if (status)
+ goto unwind;
- _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, edge, right);
+ status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, edge, right);
+ if (status)
+ goto unwind;
#if DEBUG_PRINT_STATE
print_state ("After processing start", &event_queue, &sweep_line);
@@ -1326,7 +1338,9 @@ _cairo_bentley_ottmann_tessellate_bo_edges (cairo_bo_edge_t *edges,
if (status)
goto unwind;
- _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, right);
+ status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, right);
+ if (status)
+ goto unwind;
#if DEBUG_PRINT_STATE
print_state ("After processing stop", &event_queue, &sweep_line);
@@ -1354,11 +1368,15 @@ _cairo_bentley_ottmann_tessellate_bo_edges (cairo_bo_edge_t *edges,
/* after the swap e2 is left of e1 */
- _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue,
+ status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue,
left, edge2);
+ if (status)
+ goto unwind;
- _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue,
+ status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue,
edge1, right);
+ if (status)
+ goto unwind;
#if DEBUG_PRINT_STATE
print_state ("After processing intersection", &event_queue, &sweep_line);
diff --git a/src/cairo-clip-private.h b/src/cairo-clip-private.h
index c2d2036..12f4194 100644
--- a/src/cairo-clip-private.h
+++ b/src/cairo-clip-private.h
@@ -86,10 +86,10 @@ _cairo_clip_init (cairo_clip_t *clip, cairo_surface_t *target);
cairo_private_no_warn void
_cairo_clip_fini (cairo_clip_t *clip);
-cairo_private_no_warn void
+cairo_private cairo_status_t
_cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other);
-cairo_private_no_warn void
+cairo_private cairo_status_t
_cairo_clip_init_deep_copy (cairo_clip_t *clip,
cairo_clip_t *other,
cairo_surface_t *target);
diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index efecd89..0e7d2a8 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -82,7 +82,7 @@ _cairo_clip_fini (cairo_clip_t *clip)
clip->path = NULL;
}
-void
+cairo_status_t
_cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other)
{
clip->mode = other->mode;
@@ -96,10 +96,15 @@ _cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other)
clip->region = other->region;
} else {
clip->region = pixman_region_create ();
+ if (clip->region == NULL) {
+ cairo_surface_destroy (clip->surface);
+ return CAIRO_STATUS_NO_MEMORY;
+ }
pixman_region_copy (clip->region, other->region);
}
clip->path = _cairo_clip_path_reference (other->path);
+ return CAIRO_STATUS_SUCCESS;
}
cairo_status_t
@@ -270,7 +275,7 @@ _cairo_clip_combine_to_surface (cairo_clip_t *clip,
return status;
}
-static cairo_status_t
+cairo_static cairo_status_t
_cairo_clip_intersect_path (cairo_clip_t *clip,
cairo_path_fixed_t *path,
cairo_fill_rule_t fill_rule,
@@ -535,25 +540,30 @@ _cairo_clip_translate (cairo_clip_t *clip,
}
}
-static void
+cairo_static cairo_status_t
_cairo_clip_path_reapply_clip_path (cairo_clip_t *clip,
cairo_clip_path_t *clip_path)
{
- if (clip_path->prev)
- _cairo_clip_path_reapply_clip_path (clip, clip_path->prev);
+ if (clip_path->prev) {
+ cairo_status_t status;
+ status = _cairo_clip_path_reapply_clip_path (clip, clip_path->prev);
+ if (status)
+ return status;
+ }
- _cairo_clip_intersect_path (clip,
+ return _cairo_clip_intersect_path (clip,
&clip_path->path,
clip_path->fill_rule,
clip_path->tolerance,
clip_path->antialias);
}
-void
+cairo_status_t
_cairo_clip_init_deep_copy (cairo_clip_t *clip,
cairo_clip_t *other,
cairo_surface_t *target)
{
+ cairo_status_t status;
_cairo_clip_init (clip, target);
if (other->mode != clip->mode) {
@@ -562,23 +572,42 @@ _cairo_clip_init_deep_copy (cairo_clip_t *clip,
} else {
if (other->region) {
clip->region = pixman_region_create ();
+ if (clip->region == NULL)
+ return CAIRO_STATUS_NO_MEMORY;
pixman_region_copy (clip->region, other->region);
}
if (other->surface) {
- _cairo_surface_clone_similar (target, other->surface,
- other->surface_rect.x,
- other->surface_rect.y,
- other->surface_rect.width,
- other->surface_rect.height,
- &clip->surface);
+ status = _cairo_surface_clone_similar (target, other->surface,
+ other->surface_rect.x,
+ other->surface_rect.y,
+ other->surface_rect.width,
+ other->surface_rect.height,
+ &clip->surface);
+ if (status)
+ goto BAIL;
clip->surface_rect = other->surface_rect;
}
if (other->path) {
- _cairo_clip_path_reapply_clip_path (clip, other->path);
+ status = _cairo_clip_path_reapply_clip_path (clip, other->path);
+ if (status)
+ goto BAIL;
}
}
+
+ return CAIRO_STATUS_SUCCESS;
+
+BAIL:
+ if (clip->region) {
+ pixman_region_destroy (clip->region);
+ clip->region = NULL;
+ }
+ if (clip->surface) {
+ cairo_surface_destroy (clip->surface);
+ clip->surface = NULL;
+ }
+ return status;
}
const cairo_rectangle_list_t _cairo_rectangles_nil =
@@ -635,10 +664,12 @@ _cairo_clip_copy_rectangle_list (cairo_clip_t *clip, cairo_gstate_t *gstate)
}
} else {
cairo_rectangle_int16_t extents;
- _cairo_surface_get_extents (_cairo_gstate_get_target (gstate), &extents);
- if (!_cairo_clip_rect_to_user(gstate, extents.x, extents.y,
- extents.width, extents.height,
- rectangles)) {
+ cairo_status_t status;
+ status = _cairo_surface_get_extents (_cairo_gstate_get_target (gstate), &extents);
+ if (status != CAIRO_STATUS_SUCCESS ||
+ !_cairo_clip_rect_to_user(gstate, extents.x, extents.y,
+ extents.width, extents.height,
+ rectangles)) {
free (rectangles);
return (cairo_rectangle_list_t*)
&_cairo_rectangles_not_representable;
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 7f10fd7..08677d2 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -572,10 +572,11 @@ _cairo_ft_unscaled_font_unlock_face (cairo_ft_unscaled_font_t *unscaled)
}
slim_hidden_def (cairo_ft_scaled_font_unlock_face);
-static void
+cairo_static cairo_status_t
_compute_transform (cairo_ft_font_transform_t *sf,
cairo_matrix_t *scale)
{
+ cairo_status_t status;
cairo_matrix_t normalized = *scale;
double tx, ty;
@@ -586,9 +587,11 @@ _compute_transform (cairo_ft_font_transform_t *sf,
* freetype's transformation.
*/
- _cairo_matrix_compute_scale_factors (&normalized,
- &sf->x_scale, &sf->y_scale,
- /* XXX */ 1);
+ status = _cairo_matrix_compute_scale_factors (&normalized,
+ &sf->x_scale, &sf->y_scale,
+ /* XXX */ 1);
+ if (status)
+ return status;
if (sf->x_scale != 0 && sf->y_scale != 0) {
cairo_matrix_scale (&normalized, 1.0 / sf->x_scale, 1.0 / sf->y_scale);
@@ -601,15 +604,18 @@ _compute_transform (cairo_ft_font_transform_t *sf,
sf->shape[0][0] = sf->shape[1][1] = 1.0;
sf->shape[0][1] = sf->shape[1][0] = 0.0;
}
+
+ return CAIRO_STATUS_SUCCESS;
}
/* Temporarily scales an unscaled font to the give scale. We catch
* scaling to the same size, since changing a FT_Face is expensive.
*/
-static void
+cairo_static cairo_status_t
_cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
cairo_matrix_t *scale)
{
+ cairo_status_t status;
cairo_ft_font_transform_t sf;
FT_Matrix mat;
FT_Error error;
@@ -621,12 +627,12 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
scale->yx == unscaled->current_scale.yx &&
scale->xy == unscaled->current_scale.xy &&
scale->yy == unscaled->current_scale.yy)
- return;
+ return CAIRO_STATUS_SUCCESS;
unscaled->have_scale = TRUE;
unscaled->current_scale = *scale;
- _compute_transform (&sf, scale);
+ status = _compute_transform (&sf, scale);
unscaled->x_scale = sf.x_scale;
unscaled->y_scale = sf.y_scale;
@@ -685,6 +691,8 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
unscaled->face->available_sizes[best_i].height);
assert (error == 0);
}
+
+ return CAIRO_STATUS_SUCCESS;
}
/* Empirically-derived subpixel filtering values thanks to Keith
@@ -1154,23 +1162,31 @@ _transform_glyph_bitmap (cairo_matrix_t * shape,
/* Initialize it to empty
*/
- _cairo_surface_fill_rectangle (image, CAIRO_OPERATOR_CLEAR,
- CAIRO_COLOR_TRANSPARENT,
- 0, 0,
- width, height);
+ status = _cairo_surface_fill_rectangle (image, CAIRO_OPERATOR_CLEAR,
+ CAIRO_COLOR_TRANSPARENT,
+ 0, 0,
+ width, height);
+ if (status) {
+ cairo_surface_destroy (image);
+ return status;
+ }
/* Draw the original bitmap transformed into the new bitmap
*/
_cairo_pattern_init_for_surface (&pattern, &(*surface)->base);
cairo_pattern_set_matrix (&pattern.base, &transformed_to_original);
- _cairo_surface_composite (CAIRO_OPERATOR_OVER,
- &pattern.base, NULL, image,
- 0, 0, 0, 0, 0, 0,
- width,
- height);
+ status = _cairo_surface_composite (CAIRO_OPERATOR_OVER,
+ &pattern.base, NULL, image,
+ 0, 0, 0, 0, 0, 0,
+ width, height);
_cairo_pattern_fini (&pattern.base);
+
+ if (status) {
+ cairo_surface_destroy (image);
+ return status;
+ }
/* Now update the cache entry for the new bitmap, recomputing
* the origin based on the final transform.
@@ -1417,6 +1433,7 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t *unscaled,
const cairo_font_options_t *options,
cairo_ft_options_t ft_options)
{
+ cairo_status_t status;
cairo_ft_scaled_font_t *scaled_font = NULL;
FT_Face face;
FT_Size_Metrics *metrics;
@@ -1441,13 +1458,19 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t *unscaled,
_cairo_font_options_init_copy (&scaled_font->ft_options.base, options);
_cairo_ft_options_merge (&scaled_font->ft_options, &ft_options);
- _cairo_scaled_font_init (&scaled_font->base,
- font_face,
- font_matrix, ctm, options,
- &cairo_ft_scaled_font_backend);
+ status = _cairo_scaled_font_init (&scaled_font->base,
+ font_face,
+ font_matrix, ctm, options,
+ &cairo_ft_scaled_font_backend);
+ if (status) {
+ goto UNLOCK;
+ }
- _cairo_ft_unscaled_font_set_scale (unscaled,
- &scaled_font->base.scale);
+ status = _cairo_ft_unscaled_font_set_scale (unscaled,
+ &scaled_font->base.scale);
+ if (status) {
+ goto UNLOCK;
+ }
metrics = &face->size->metrics;
@@ -1498,6 +1521,11 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t *unscaled,
_cairo_ft_unscaled_font_unlock_face (unscaled);
return &scaled_font->base;
+
+UNLOCK:
+ free (scaled_font);
+ _cairo_ft_unscaled_font_unlock_face (unscaled);
+ return NULL;
}
cairo_bool_t
@@ -1514,6 +1542,7 @@ _cairo_ft_scaled_font_create_toy (cairo_toy_font_face_t *toy_face,
cairo_scaled_font_t **font)
{
FcPattern *pattern, *resolved;
+ cairo_status_t status = CAIRO_STATUS_SUCCESS;
cairo_ft_unscaled_font_t *unscaled;
cairo_scaled_font_t *new_font = NULL;
FcResult result;
@@ -1561,7 +1590,7 @@ _cairo_ft_scaled_font_create_toy (cairo_toy_font_face_t *toy_face,
goto FREE_PATTERN;
cairo_matrix_multiply (&scale, font_matrix, ctm);
- _compute_transform (&sf, &scale);
+ status = _compute_transform (&sf, &scale);
FcPatternAddInteger (pattern, FC_PIXEL_SIZE, sf.y_scale);
@@ -1594,10 +1623,11 @@ _cairo_ft_scaled_font_create_toy (cairo_toy_font_face_t *toy_face,
if (new_font) {
*font = new_font;
- return CAIRO_STATUS_SUCCESS;
} else {
- return CAIRO_STATUS_NO_MEMORY;
+ if (status == CAIRO_STATUS_SUCCESS)
+ status = CAIRO_STATUS_NO_MEMORY;
}
+ return status;
}
static void
@@ -1719,6 +1749,7 @@ _decompose_glyph_outline (FT_Face face,
FT_GlyphSlot glyph;
cairo_path_fixed_t *path;
+ cairo_status_t status;
path = _cairo_path_fixed_create ();
if (!path)
@@ -1728,9 +1759,16 @@ _decompose_glyph_outline (FT_Face face,
/* Font glyphs have an inverted Y axis compared to cairo. */
FT_Outline_Transform (&glyph->outline, &invert_y);
- FT_Outline_Decompose (&glyph->outline, &outline_funcs, path);
+ if (FT_Outline_Decompose (&glyph->outline, &outline_funcs, path) != 0) {
+ _cairo_path_fixed_destroy (path);
+ return CAIRO_STATUS_NO_MEMORY;
+ }
- _cairo_path_fixed_close_path (path);
+ status = _cairo_path_fixed_close_path (path);
+ if (status != CAIRO_STATUS_SUCCESS) {
+ _cairo_path_fixed_destroy (path);
+ return status;
+ }
*pathp = path;
@@ -1774,14 +1812,16 @@ _cairo_ft_scaled_glyph_init (void *abstract_font,
FT_Glyph_Metrics *metrics;
double x_factor, y_factor;
cairo_bool_t vertical_layout = FALSE;
- cairo_status_t status = CAIRO_STATUS_SUCCESS;
+ cairo_status_t status;
face = _cairo_ft_unscaled_font_lock_face (unscaled);
if (!face)
return CAIRO_STATUS_NO_MEMORY;
- _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled,
- &scaled_font->base.scale);
+ status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled,
+ &scaled_font->base.scale);
+ if (status)
+ return status;
/* Ignore global advance unconditionally */
load_flags |= FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH;
@@ -2447,6 +2487,7 @@ FT_Face
cairo_ft_scaled_font_lock_face (cairo_scaled_font_t *abstract_font)
{
cairo_ft_scaled_font_t *scaled_font = (cairo_ft_scaled_font_t *) abstract_font;
+ cairo_status_t status;
FT_Face face;
if (scaled_font->base.status)
@@ -2458,8 +2499,12 @@ cairo_ft_scaled_font_lock_face (cairo_scaled_font_t *abstract_font)
return NULL;
}
- _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled,
+ status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled,
&scaled_font->base.scale);
+ if (status) {
+ _cairo_scaled_font_set_error (&scaled_font->base, status);
+ return NULL;
+ }
/* NOTE: We deliberately release the unscaled font's mutex here,
* so that we are not holding a lock across two separate calls to
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index b75a90b..155ee9c 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -64,6 +64,8 @@ cairo_status_t
_cairo_gstate_init (cairo_gstate_t *gstate,
cairo_surface_t *target)
{
+ cairo_status_t status;
+
gstate->op = CAIRO_GSTATE_OPERATOR_DEFAULT;
gstate->tolerance = CAIRO_GSTATE_TOLERANCE_DEFAULT;
@@ -88,7 +90,9 @@ _cairo_gstate_init (cairo_gstate_t *gstate,
gstate->parent_target = NULL;
gstate->original_target = cairo_surface_reference (target);
- _cairo_gstate_identity_matrix (gstate);
+ status = _cairo_gstate_identity_matrix (gstate);
+ if (status != CAIRO_STATUS_SUCCESS)
+ return status;
gstate->source_ctm_inverse = gstate->ctm_inverse;
gstate->source = _cairo_pattern_create_solid (CAIRO_COLOR_BLACK);
@@ -122,6 +126,12 @@ _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other)
if (status)
return status;
+ status = _cairo_clip_init_copy (&gstate->clip, &other->clip);
+ if (status) {
+ _cairo_stroke_style_fini (&gstate->stroke_style);
+ return status;
+ }
+
gstate->fill_rule = other->fill_rule;
gstate->font_face = cairo_font_face_reference (other->font_face);
@@ -131,7 +141,6 @@ _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other)
_cairo_font_options_init_copy (&gstate->font_options , &other->font_options);
- _cairo_clip_init_copy (&gstate->clip, &other->clip);
gstate->target = cairo_surface_reference (other->target);
/* parent_target is always set to NULL; it's only ever set by redirect_target */
@@ -252,9 +261,10 @@ _cairo_gstate_recursive_apply_clip_path (cairo_gstate_t *gstate,
* original #cairo_t target, the clip will be INVALID after this call,
* and the caller should either recreate or reset the clip.
**/
-void
+cairo_status_t
_cairo_gstate_redirect_target (cairo_gstate_t *gstate, cairo_surface_t *child)
{
+ cairo_status_t status;
/* If this gstate is already redirected, this is an error; we need a
* new gstate to be able to redirect */
assert (gstate->parent_target == NULL);
@@ -270,13 +280,17 @@ _cairo_gstate_redirect_target (cairo_gstate_t *gstate, cairo_surface_t *child)
gstate->target = cairo_surface_reference (child);
_cairo_clip_fini (&gstate->clip);
- _cairo_clip_init_deep_copy (&gstate->clip, &gstate->next->clip, child);
+ status = _cairo_clip_init_deep_copy (&gstate->clip, &gstate->next->clip, child);
+ if (status)
+ return status;
/* The clip is in surface backend coordinates for the previous target;
* translate it into the child's backend coordinates. */
_cairo_clip_translate (&gstate->clip,
_cairo_fixed_from_double (child->device_transform.x0 - gstate->parent_target->device_transform.x0),
_cairo_fixed_from_double (child->device_transform.y0 - gstate->parent_target->device_transform.y0));
+
+ return CAIRO_STATUS_SUCCESS;
}
/**
@@ -583,13 +597,16 @@ _cairo_gstate_transform (cairo_gstate_t *gstate,
const cairo_matrix_t *matrix)
{
cairo_matrix_t tmp;
+ cairo_status_t status;
_cairo_gstate_unset_scaled_font (gstate);
tmp = *matrix;
cairo_matrix_multiply (&gstate->ctm, &tmp, &gstate->ctm);
- cairo_matrix_invert (&tmp);
+ status = cairo_matrix_invert (&tmp);
+ if (status)
+ return status;
cairo_matrix_multiply (&gstate->ctm_inverse, &gstate->ctm_inverse, &tmp);
return CAIRO_STATUS_SUCCESS;
@@ -1190,15 +1207,16 @@ _cairo_gstate_select_font_face (cairo_gstate_t *gstate,
cairo_font_weight_t weight)
{
cairo_font_face_t *font_face;
+ cairo_status_t status;
font_face = _cairo_toy_font_face_create (family, slant, weight);
if (font_face->status)
return font_face->status;
- _cairo_gstate_set_font_face (gstate, font_face);
+ status = _cairo_gstate_set_font_face (gstate, font_face);
cairo_font_face_destroy (font_face);
- return CAIRO_STATUS_SUCCESS;
+ return status;
}
cairo_status_t
diff --git a/src/cairo-meta-surface.c b/src/cairo-meta-surface.c
index e196df2..7bbdc39 100644
--- a/src/cairo-meta-surface.c
+++ b/src/cairo-meta-surface.c
@@ -668,7 +668,9 @@ _cairo_meta_surface_replay (cairo_surface_t *surface,
dev_path = _cairo_command_get_path (command);
if (dev_path && has_device_transform) {
- _cairo_path_fixed_init_copy (&path_copy, dev_path);
+ status = _cairo_path_fixed_init_copy (&path_copy, dev_path);
+ if (status)
+ break;
_cairo_path_fixed_device_transform (&path_copy, device_transform);
dev_path = &path_copy;
}
diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c
index 64a9cbf..b8e87ac 100644
--- a/src/cairo-paginated-surface.c
+++ b/src/cairo-paginated-surface.c
@@ -201,15 +201,22 @@ _cairo_paginated_surface_acquire_source_image (void *abstract_surface,
{
cairo_paginated_surface_t *surface = abstract_surface;
cairo_surface_t *image;
+ cairo_status_t status;
cairo_rectangle_int16_t extents;
- _cairo_surface_get_extents (surface->target, &extents);
+ status = _cairo_surface_get_extents (surface->target, &extents);
+ if (status)
+ return status;
image = _cairo_paginated_surface_create_image_surface (surface,
extents.width,
extents.height);
- _cairo_meta_surface_replay (surface->meta, image);
+ status = _cairo_meta_surface_replay (surface->meta, image);
+ if (status) {
+ cairo_surface_destroy (image);
+ return status;
+ }
*image_out = (cairo_image_surface_t*) image;
*image_extra = NULL;
@@ -257,7 +264,7 @@ _paint_page (cairo_paginated_surface_t *surface)
surface->height * y_scale);
_cairo_surface_set_device_scale (image, x_scale, y_scale);
- _cairo_meta_surface_replay (surface->meta, image);
+ status = _cairo_meta_surface_replay (surface->meta, image);
pattern = cairo_pattern_create_for_surface (image);
cairo_matrix_init_scale (&matrix, x_scale, y_scale);
@@ -271,12 +278,12 @@ _paint_page (cairo_paginated_surface_t *surface)
}
else
{
- _cairo_meta_surface_replay (surface->meta, surface->target);
+ status = _cairo_meta_surface_replay (surface->meta, surface->target);
}
cairo_surface_destroy (analysis);
- return CAIRO_STATUS_SUCCESS;
+ return status;
}
static cairo_status_t
@@ -325,7 +332,9 @@ _cairo_paginated_surface_show_page (void *abstract_surface)
_paint_page (surface);
- _cairo_surface_show_page (surface->target);
+ status = _cairo_surface_show_page (surface->target);
+ if (status)
+ return status;
cairo_surface_destroy (surface->meta);
@@ -503,15 +512,23 @@ _cairo_paginated_surface_snapshot (void *abstract_other)
return _cairo_surface_snapshot (other->meta);
#else
cairo_rectangle_int16_t extents;
+ cairo_status_t status;
cairo_surface_t *surface;
- _cairo_surface_get_extents (other->target, &extents);
+ status = _cairo_surface_get_extents (other->target, &extents);
+ if (status) {
+ return (cairo_surface_t *) &_cairo_surface_nil;
+ }
surface = _cairo_paginated_surface_create_image_surface (other,
extents.width,
extents.height);
- _cairo_meta_surface_replay (other->meta, surface);
+ status = _cairo_meta_surface_replay (other->meta, surface);
+ if (status) {
+ cairo_surface_destroy (surface);
+ return (cairo_surface_t *) &_cairo_surface_nil;
+ }
return surface;
#endif
diff --git a/src/cairo-path-fill.c b/src/cairo-path-fill.c
index b1b7a12..d2a9118 100644
--- a/src/cairo-path-fill.c
+++ b/src/cairo-path-fill.c
@@ -138,7 +138,7 @@ _cairo_filler_curve_to (void *closure,
if (status == CAIRO_INT_STATUS_DEGENERATE)
return CAIRO_STATUS_SUCCESS;
- _cairo_spline_decompose (&spline, filler->tolerance);
+ status = _cairo_spline_decompose (&spline, filler->tolerance);
if (status)
goto CLEANUP_SPLINE;
diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c
index 09bafbf..61d008f 100644
--- a/src/cairo-path-stroke.c
+++ b/src/cairo-path-stroke.c
@@ -67,7 +67,7 @@ typedef struct cairo_stroker {
} cairo_stroker_t;
/* private functions */
-static void
+cairo_static cairo_status_t
_cairo_stroker_init (cairo_stroker_t *stroker,
cairo_stroke_style_t *stroke_style,
cairo_matrix_t *ctm,
@@ -75,43 +75,44 @@ _cairo_stroker_init (cairo_stroker_t *stroker,
double tolerance,
cairo_traps_t *traps);
-static void
+cairo_static cairo_status_t
_cairo_stroker_fini (cairo_stroker_t *stroker);
-static cairo_status_t
+cairo_static cairo_status_t
_cairo_stroker_move_to (void *closure, cairo_point_t *point);
-static cairo_status_t
+cairo_static cairo_status_t
_cairo_stroker_line_to (void *closure, cairo_point_t *point);
-static cairo_status_t
+cairo_static cairo_status_t
_cairo_stroker_line_to_dashed (void *closure, cairo_point_t *point);
-static cairo_status_t
+cairo_static cairo_status_t
_cairo_stroker_curve_to (void *closure,
cairo_point_t *b,
cairo_point_t *c,
cairo_point_t *d);
-static cairo_status_t
+cairo_static cairo_status_t
_cairo_stroker_curve_to_dashed (void *closure,
cairo_point_t *b,
cairo_point_t *c,
cairo_point_t *d);
-static cairo_status_t
+cairo_static cairo_status_t
_cairo_stroker_close_path (void *closure);
-static void
-_translate_point (cairo_point_t *point, cairo_point_t *offset);
-
-static int
+cairo_static int
_cairo_stroker_face_clockwise (cairo_stroke_face_t *in, cairo_stroke_face_t *out);
-static cairo_status_t
+cairo_static cairo_status_t
_cairo_stroker_join (cairo_stroker_t *stroker, cairo_stroke_face_t *in, cairo_stroke_face_t *out);
static void
+_translate_point (cairo_point_t *point, cairo_point_t *offset);
+
+
+static void
_cairo_stroker_start_dash (cairo_stroker_t *stroker)
{
double offset;
@@ -148,7 +149,7 @@ _cairo_stroker_step_dash (cairo_stroker_t *stroker, double step)
}
}
-static void
+static cairo_status_t
_cairo_stroker_init (cairo_stroker_t *stroker,
cairo_stroke_style_t *stroke_style,
cairo_matrix_t *ctm,
@@ -156,15 +157,19 @@ _cairo_stroker_init (cairo_stroker_t *stroker,
double tolerance,
cairo_traps_t *traps)
{
+ cairo_status_t status;
+
stroker->style = stroke_style;
stroker->ctm = ctm;
stroker->ctm_inverse = ctm_inverse;
stroker->tolerance = tolerance;
stroker->traps = traps;
- _cairo_pen_init (&stroker->pen,
- stroke_style->line_width / 2.0,
- tolerance, ctm);
+ status = _cairo_pen_init (&stroker->pen,
+ stroke_style->line_width / 2.0,
+ tolerance, ctm);
+ if (status)
+ return status;
stroker->has_current_face = FALSE;
stroker->has_first_face = FALSE;
@@ -174,12 +179,14 @@ _cairo_stroker_init (cairo_stroker_t *stroker,
_cairo_stroker_start_dash (stroker);
else
stroker->dashed = FALSE;
+
+ return status;
}
-static void
+static cairo_status_t
_cairo_stroker_fini (cairo_stroker_t *stroker)
{
- _cairo_pen_fini (&stroker->pen);
+ return _cairo_pen_fini (&stroker->pen);
}
static void
@@ -205,6 +212,7 @@ _cairo_stroker_join (cairo_stroker_t *stroker, cairo_stroke_face_t *in, cairo_st
{
int clockwise = _cairo_stroker_face_clockwise (out, in);
cairo_point_t *inpt, *outpt;
+ cairo_status_t status;
if (in->cw.x == out->cw.x
&& in->cw.y == out->cw.y
@@ -231,13 +239,21 @@ _cairo_stroker_join (cairo_stroker_t *stroker, cairo_stroke_face_t *in, cairo_st
tri[0] = in->point;
if (clockwise) {
- _cairo_pen_find_active_ccw_vertex_index (pen, &in->dev_vector, &start);
+ status = _cairo_pen_find_active_ccw_vertex_index (pen, &in->dev_vector, &start);
+ if (status)
+ return status;
step = -1;
- _cairo_pen_find_active_ccw_vertex_index (pen, &out->dev_vector, &stop);
+ status = _cairo_pen_find_active_ccw_vertex_index (pen, &out->dev_vector, &stop);
+ if (status)
+ return status;
} else {
- _cairo_pen_find_active_cw_vertex_index (pen, &in->dev_vector, &start);
+ status = _cairo_pen_find_active_cw_vertex_index (pen, &in->dev_vector, &start);
+ if (status)
+ return status;
step = +1;
- _cairo_pen_find_active_cw_vertex_index (pen, &out->dev_vector, &stop);
+ status = _cairo_pen_find_active_cw_vertex_index (pen, &out->dev_vector, &stop);
+ if (status)
+ return status;
}
i = start;
@@ -245,7 +261,9 @@ _cairo_stroker_join (cairo_stroker_t *stroker, cairo_stroke_face_t *in, cairo_st
while (i != stop) {
tri[2] = in->point;
_translate_point (&tri[2], &pen->vertices[i].point);
- _cairo_traps_tessellate_triangle (stroker->traps, tri);
+ status = _cairo_traps_tessellate_triangle (stroker->traps, tri);
+ if (status)
+ return status;
tri[1] = tri[2];
i += step;
if (i < 0)
@@ -378,17 +396,23 @@ _cairo_stroker_add_cap (cairo_stroker_t *stroker, cairo_stroke_face_t *f)
cairo_pen_t *pen = &stroker->pen;
slope = f->dev_vector;
- _cairo_pen_find_active_cw_vertex_index (pen, &slope, &start);
+ status = _cairo_pen_find_active_cw_vertex_index (pen, &slope, &start);
+ if (status)
+ return status;
slope.dx = -slope.dx;
slope.dy = -slope.dy;
- _cairo_pen_find_active_cw_vertex_index (pen, &slope, &stop);
+ status = _cairo_pen_find_active_cw_vertex_index (pen, &slope, &stop);
+ if (status)
+ return status;
tri[0] = f->point;
tri[1] = f->cw;
for (i=start; i != stop; i = (i+1) % pen->num_vertices) {
tri[2] = f->point;
_translate_point (&tri[2], &pen->vertices[i].point);
- _cairo_traps_tessellate_triangle (stroker->traps, tri);
+ status = _cairo_traps_tessellate_triangle (stroker->traps, tri);
+ if (status)
+ return status;
tri[1] = tri[2];
}
tri[2] = f->ccw;
@@ -414,13 +438,24 @@ _cairo_stroker_add_cap (cairo_stroker_t *stroker, cairo_stroke_face_t *f)
ocw.y = f->cw.y + fvector.dy;
_cairo_polygon_init (&polygon);
- _cairo_polygon_move_to (&polygon, &f->cw);
- _cairo_polygon_line_to (&polygon, &ocw);
- _cairo_polygon_line_to (&polygon, &occw);
- _cairo_polygon_line_to (&polygon, &f->ccw);
- _cairo_polygon_close (&polygon);
+ status = _cairo_polygon_move_to (&polygon, &f->cw);
+ if (status)
+ goto CLEANUP_LINE_CAP_SQUARE;
+ status = _cairo_polygon_line_to (&polygon, &ocw);
+ if (status)
+ goto CLEANUP_LINE_CAP_SQUARE;
+ status = _cairo_polygon_line_to (&polygon, &occw);
+ if (status)
+ goto CLEANUP_LINE_CAP_SQUARE;
+ status = _cairo_polygon_line_to (&polygon, &f->ccw);
+ if (status)
+ goto CLEANUP_LINE_CAP_SQUARE;
+ status = _cairo_polygon_close (&polygon);
+ if (status)
+ goto CLEANUP_LINE_CAP_SQUARE;
status = _cairo_bentley_ottmann_tessellate_polygon (stroker->traps, &polygon, CAIRO_FILL_RULE_WINDING);
+CLEANUP_LINE_CAP_SQUARE:
_cairo_polygon_fini (&polygon);
return status;
@@ -778,7 +813,8 @@ _cairo_stroker_curve_to (void *closure,
cairo_point_t *c,
cairo_point_t *d)
{
- cairo_status_t status = CAIRO_STATUS_SUCCESS;
+ cairo_status_t status;
+ cairo_status_t status2;
cairo_stroker_t *stroker = closure;
cairo_spline_t spline;
cairo_pen_t pen;
@@ -830,7 +866,9 @@ _cairo_stroker_curve_to (void *closure,
goto CLEANUP_PEN;
CLEANUP_PEN:
- _cairo_pen_fini (&pen);
+ status2 = _cairo_pen_fini (&pen);
+ if (status == CAIRO_STATUS_SUCCESS)
+ status = status2;
CLEANUP_SPLINE:
_cairo_spline_fini (&spline);
@@ -953,6 +991,7 @@ _cairo_path_fixed_stroke_to_traps (cairo_path_fixed_t *path,
cairo_traps_t *traps)
{
cairo_status_t status;
+ cairo_status_t status2;
cairo_stroker_t stroker;
/* Before we do anything else, we attempt the rectilinear
@@ -967,9 +1006,11 @@ _cairo_path_fixed_stroke_to_traps (cairo_path_fixed_t *path,
if (status != CAIRO_INT_STATUS_UNSUPPORTED)
return status;
- _cairo_stroker_init (&stroker, stroke_style,
- ctm, ctm_inverse, tolerance,
- traps);
+ status = _cairo_stroker_init (&stroker, stroke_style,
+ ctm, ctm_inverse, tolerance,
+ traps);
+ if (status)
+ return status;
if (stroker.style->dash)
status = _cairo_path_fixed_interpret (path,
@@ -994,7 +1035,9 @@ _cairo_path_fixed_stroke_to_traps (cairo_path_fixed_t *path,
status = _cairo_stroker_add_caps (&stroker);
BAIL:
- _cairo_stroker_fini (&stroker);
+ status2 = _cairo_stroker_fini (&stroker);
+ if (status == CAIRO_STATUS_SUCCESS)
+ status = status2;
return status;
}
diff --git a/src/cairo-path.c b/src/cairo-path.c
index 7c2374c..1219f83 100644
--- a/src/cairo-path.c
+++ b/src/cairo-path.c
@@ -136,21 +136,24 @@ _cairo_path_count (cairo_path_t *path,
cairo_bool_t flatten)
{
cpc_t cpc;
+ cairo_status_t status;
cpc.count = 0;
cpc.tolerance = tolerance;
cpc.current_point.x = 0;
cpc.current_point.y = 0;
- _cairo_path_fixed_interpret (path_fixed,
- CAIRO_DIRECTION_FORWARD,
- _cpc_move_to,
- _cpc_line_to,
- flatten ?
- _cpc_curve_to_flatten :
- _cpc_curve_to,
- _cpc_close_path,
- &cpc);
+ status = _cairo_path_fixed_interpret (path_fixed,
+ CAIRO_DIRECTION_FORWARD,
+ _cpc_move_to,
+ _cpc_line_to,
+ flatten ?
+ _cpc_curve_to_flatten :
+ _cpc_curve_to,
+ _cpc_close_path,
+ &cpc);
+ if (status)
+ return 0;
return cpc.count;
}
@@ -305,31 +308,34 @@ _cpp_close_path (void *closure)
return CAIRO_STATUS_SUCCESS;
}
-static void
+static cairo_status_t
_cairo_path_populate (cairo_path_t *path,
cairo_path_fixed_t *path_fixed,
cairo_gstate_t *gstate,
cairo_bool_t flatten)
{
cpp_t cpp;
+ cairo_status_t status;
cpp.data = path->data;
cpp.gstate = gstate;
cpp.current_point.x = 0;
cpp.current_point.y = 0;
- _cairo_path_fixed_interpret (path_fixed,
- CAIRO_DIRECTION_FORWARD,
- _cpp_move_to,
- _cpp_line_to,
- flatten ?
- _cpp_curve_to_flatten :
- _cpp_curve_to,
- _cpp_close_path,
- &cpp);
+ status = _cairo_path_fixed_interpret (path_fixed,
+ CAIRO_DIRECTION_FORWARD,
+ _cpp_move_to,
+ _cpp_line_to,
+ flatten ?
+ _cpp_curve_to_flatten :
+ _cpp_curve_to,
+ _cpp_close_path,
+ &cpp);
/* Sanity check the count */
assert (cpp.data - path->data == path->num_data);
+
+ return status;
}
cairo_path_t *
@@ -368,10 +374,8 @@ _cairo_path_create_internal (cairo_path_fixed_t *path_fixed,
return (cairo_path_t*) &_cairo_path_nil;
}
- path->status = CAIRO_STATUS_SUCCESS;
-
- _cairo_path_populate (path, path_fixed,
- gstate, flatten);
+ path->status = _cairo_path_populate (path, path_fixed,
+ gstate, flatten);
return path;
}
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index beb95e8..bfd119a 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -1738,7 +1738,9 @@ _cairo_pattern_get_extents (cairo_pattern_t *pattern,
return status;
imatrix = pattern->matrix;
- cairo_matrix_invert (&imatrix);
+ status = cairo_matrix_invert (&imatrix);
+ if (status)
+ return status;
/* XXX Use _cairo_matrix_transform_bounding_box here */
for (sy = 0; sy <= 1; sy++) {
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 924b80c..cdf3d2b 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -900,7 +900,9 @@ _cairo_pdf_surface_emit_surface_pattern (cairo_pdf_surface_t *surface,
if (status)
goto BAIL;
- _cairo_surface_get_extents (&surface->base, &surface_extents);
+ status = _cairo_surface_get_extents (&surface->base, &surface_extents);
+ if (status)
+ goto BAIL;
switch (extend) {
/* We implement EXTEND_PAD like EXTEND_NONE for now */
@@ -974,7 +976,9 @@ _cairo_pdf_surface_emit_surface_pattern (cairo_pdf_surface_t *surface,
* pattern cell.
*/
cairo_p2d = pattern->base.matrix;
- cairo_matrix_invert (&cairo_p2d);
+ status = cairo_matrix_invert (&cairo_p2d);
+ if (status)
+ goto BAIL;
cairo_matrix_init_identity (&pdf_p2d);
cairo_matrix_translate (&pdf_p2d, 0.0, surface_extents.height);
@@ -1187,6 +1191,7 @@ _cairo_pdf_surface_emit_pattern_stops (cairo_pdf_surface_t *surface, cairo_gradi
static cairo_status_t
_cairo_pdf_surface_emit_linear_pattern (cairo_pdf_surface_t *surface, cairo_linear_pattern_t *pattern)
{
+ cairo_status_t status;
cairo_pdf_resource_t function, pattern_resource, alpha;
double x0, y0, x1, y1;
cairo_matrix_t p2u;
@@ -1198,7 +1203,9 @@ _cairo_pdf_surface_emit_linear_pattern (cairo_pdf_surface_t *surface, cairo_line
return CAIRO_STATUS_NO_MEMORY;
p2u = pattern->base.base.matrix;
- cairo_matrix_invert (&p2u);
+ status = cairo_matrix_invert (&p2u);
+ if (status)
+ return status;
x0 = _cairo_fixed_to_double (pattern->gradient.p1.x);
y0 = _cairo_fixed_to_double (pattern->gradient.p1.y);
@@ -1250,6 +1257,7 @@ _cairo_pdf_surface_emit_linear_pattern (cairo_pdf_surface_t *surface, cairo_line
static cairo_status_t
_cairo_pdf_surface_emit_radial_pattern (cairo_pdf_surface_t *surface, cairo_radial_pattern_t *pattern)
{
+ cairo_status_t status;
cairo_pdf_resource_t function, pattern_resource, alpha;
double x0, y0, x1, y1, r0, r1;
cairo_matrix_t p2u;
@@ -1261,7 +1269,9 @@ _cairo_pdf_surface_emit_radial_pattern (cairo_pdf_surface_t *surface, cairo_radi
return CAIRO_STATUS_NO_MEMORY;
p2u = pattern->base.base.matrix;
- cairo_matrix_invert (&p2u);
+ status = cairo_matrix_invert (&p2u);
+ if (status)
+ return status;
x0 = _cairo_fixed_to_double (pattern->gradient.c1.x);
y0 = _cairo_fixed_to_double (pattern->gradient.c1.y);
@@ -1822,11 +1832,11 @@ _cairo_pdf_surface_emit_cff_font_subset (cairo_pdf_surface_t *surface,
font.font_id = font_subset->font_id;
font.subset_id = font_subset->subset_id;
font.subset_resource = subset_resource;
- _cairo_array_append (&surface->fonts, &font);
+ status = _cairo_array_append (&surface->fonts, &font);
_cairo_cff_subset_fini (&subset);
- return CAIRO_STATUS_SUCCESS;
+ return status;
}
static cairo_status_t
@@ -1931,9 +1941,7 @@ _cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t *surface,
font.font_id = font_subset->font_id;
font.subset_id = font_subset->subset_id;
font.subset_resource = subset_resource;
- _cairo_array_append (&surface->fonts, &font);
-
- return CAIRO_STATUS_SUCCESS;
+ return _cairo_array_append (&surface->fonts, &font);
}
#if CAIRO_HAS_FT_FONT
@@ -2102,11 +2110,11 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t *surface,
font.font_id = font_subset->font_id;
font.subset_id = font_subset->subset_id;
font.subset_resource = subset_resource;
- _cairo_array_append (&surface->fonts, &font);
+ status = _cairo_array_append (&surface->fonts, &font);
_cairo_truetype_subset_fini (&subset);
- return CAIRO_STATUS_SUCCESS;
+ return status;
}
static cairo_int_status_t
@@ -2387,9 +2395,7 @@ _cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t *surface,
font.font_id = font_subset->font_id;
font.subset_id = font_subset->subset_id;
font.subset_resource = subset_resource;
- _cairo_array_append (&surface->fonts, &font);
-
- return CAIRO_STATUS_SUCCESS;
+ return _cairo_array_append (&surface->fonts, &font);
}
static void
diff --git a/src/cairo-pen.c b/src/cairo-pen.c
index 1af8c36..55f74d4 100644
--- a/src/cairo-pen.c
+++ b/src/cairo-pen.c
@@ -106,13 +106,13 @@ _cairo_pen_init (cairo_pen_t *pen,
return CAIRO_STATUS_SUCCESS;
}
-void
+cairo_status_t
_cairo_pen_fini (cairo_pen_t *pen)
{
free (pen->vertices);
pen->vertices = NULL;
- _cairo_pen_init_empty (pen);
+ return _cairo_pen_init_empty (pen);
}
cairo_status_t
@@ -135,6 +135,7 @@ cairo_status_t
_cairo_pen_add_points (cairo_pen_t *pen, cairo_point_t *point, int num_points)
{
cairo_pen_vertex_t *vertices;
+ cairo_status_t status;
int num_vertices;
int i;
@@ -150,7 +151,9 @@ _cairo_pen_add_points (cairo_pen_t *pen, cairo_point_t *point, int num_points)
for (i=0; i < num_points; i++)
pen->vertices[pen->num_vertices-num_points+i].point = point[i];
- _cairo_hull_compute (pen->vertices, &pen->num_vertices);
+ status = _cairo_hull_compute (pen->vertices, &pen->num_vertices);
+ if (status)
+ return status;
_cairo_pen_compute_slopes (pen);
@@ -388,7 +391,9 @@ _cairo_pen_stroke_spline_half (cairo_pen_t *pen,
final_slope.dy = -final_slope.dy;
}
- _cairo_pen_find_active_cw_vertex_index (pen, &initial_slope, &active);
+ status = _cairo_pen_find_active_cw_vertex_index (pen, &initial_slope, &active);
+ if (status)
+ return status;
i = start;
while (i != stop) {
@@ -437,19 +442,22 @@ _cairo_pen_stroke_spline (cairo_pen_t *pen,
status = _cairo_spline_decompose (spline, tolerance);
if (status)
- return status;
+ goto BAIL;
status = _cairo_pen_stroke_spline_half (pen, spline, CAIRO_DIRECTION_FORWARD, &polygon);
if (status)
- return status;
+ goto BAIL;
status = _cairo_pen_stroke_spline_half (pen, spline, CAIRO_DIRECTION_REVERSE, &polygon);
if (status)
- return status;
+ goto BAIL;
- _cairo_polygon_close (&polygon);
- _cairo_bentley_ottmann_tessellate_polygon (traps, &polygon, CAIRO_FILL_RULE_WINDING);
+ status = _cairo_polygon_close (&polygon);
+ if (status)
+ goto BAIL;
+ status = _cairo_bentley_ottmann_tessellate_polygon (traps, &polygon, CAIRO_FILL_RULE_WINDING);
_cairo_polygon_fini (&polygon);
- return CAIRO_STATUS_SUCCESS;
+BAIL:
+ return status;
}
diff --git a/src/cairo-polygon.c b/src/cairo-polygon.c
index f36bc71..80c89a0 100644
--- a/src/cairo-polygon.c
+++ b/src/cairo-polygon.c
@@ -135,9 +135,9 @@ _cairo_polygon_add_edge (cairo_polygon_t *polygon, cairo_point_t *p1, cairo_poin
polygon->num_edges++;
DONE:
- _cairo_polygon_move_to (polygon, p2);
+ status = _cairo_polygon_move_to (polygon, p2);
- return CAIRO_STATUS_SUCCESS;
+ return status;
}
cairo_status_t
@@ -154,12 +154,12 @@ _cairo_polygon_move_to (cairo_polygon_t *polygon, cairo_point_t *point)
cairo_status_t
_cairo_polygon_line_to (cairo_polygon_t *polygon, cairo_point_t *point)
{
- cairo_status_t status = CAIRO_STATUS_SUCCESS;
+ cairo_status_t status;
if (polygon->has_current_point) {
status = _cairo_polygon_add_edge (polygon, &polygon->current_point, point);
} else {
- _cairo_polygon_move_to (polygon, point);
+ status = _cairo_polygon_move_to (polygon, point);
}
return status;
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 5f43e98..01c5003 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -298,6 +298,7 @@ _cairo_ps_surface_emit_path (cairo_ps_surface_t *surface,
{
cairo_output_stream_t *word_wrap;
cairo_status_t status;
+ cairo_status_t status2;
ps_path_info_t path_info;
word_wrap = _word_wrap_stream_create (stream, 79);
@@ -315,7 +316,9 @@ _cairo_ps_surface_emit_path (cairo_ps_surface_t *surface,
if (status == CAIRO_STATUS_SUCCESS)
status = _cairo_output_stream_get_status (word_wrap);
- _cairo_output_stream_destroy (word_wrap);
+ status2 = _cairo_output_stream_destroy (word_wrap);
+ if (status == CAIRO_STATUS_SUCCESS)
+ status = status2;
return status;
}
@@ -834,6 +837,7 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream,
&cairo_ps_surface_paginated_backend);
CLEANUP_OUTPUT_STREAM:
+ /* ignore further errors, as we are already on an error path */
_cairo_output_stream_destroy (surface->stream);
CLEANUP_TMPFILE:
fclose (surface->tmpfile);
@@ -1202,6 +1206,7 @@ static cairo_status_t
_cairo_ps_surface_finish (void *abstract_surface)
{
cairo_status_t status;
+ cairo_status_t status2;
cairo_ps_surface_t *surface = abstract_surface;
int i, num_comments;
char **comments;
@@ -1214,16 +1219,13 @@ _cairo_ps_surface_finish (void *abstract_surface)
_cairo_ps_surface_emit_footer (surface);
- _cairo_output_stream_close (surface->stream);
- status = _cairo_output_stream_get_status (surface->stream);
- _cairo_output_stream_destroy (surface->stream);
+ status = _cairo_output_stream_destroy (surface->stream);
fclose (surface->tmpfile);
- _cairo_output_stream_close (surface->final_stream);
+ status2 = _cairo_output_stream_destroy (surface->final_stream);
if (status == CAIRO_STATUS_SUCCESS)
- status = _cairo_output_stream_get_status (surface->final_stream);
- _cairo_output_stream_destroy (surface->final_stream);
+ status = status2;
num_comments = _cairo_array_num_elements (&surface->dsc_header_comments);
comments = _cairo_array_index (&surface->dsc_header_comments, 0);
@@ -1588,23 +1590,26 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t *surface,
_cairo_pattern_init_for_surface (&pattern.surface, &image->base);
- _cairo_surface_fill_rectangle (opaque,
+ status = _cairo_surface_fill_rectangle (opaque,
CAIRO_OPERATOR_SOURCE,
CAIRO_COLOR_WHITE,
0, 0, image->width, image->height);
- _cairo_surface_composite (CAIRO_OPERATOR_OVER,
- &pattern.base,
- NULL,
- opaque,
- 0, 0,
- 0, 0,
- 0, 0,
- image->width,
- image->height);
+ if (status == CAIRO_STATUS_SUCCESS)
+ status = _cairo_surface_composite (CAIRO_OPERATOR_OVER,
+ &pattern.base,
+ NULL,
+ opaque,
+ 0, 0,
+ 0, 0,
+ 0, 0,
+ image->width,
+ image->height);
_cairo_pattern_fini (&pattern.base);
opaque_image = (cairo_image_surface_t *) opaque;
+ if (status)
+ goto bail1;
} else {
opaque = &image->base;
opaque_image = image;
@@ -1705,19 +1710,24 @@ _cairo_ps_surface_emit_solid_pattern (cairo_ps_surface_t *surface,
pattern->color.blue);
}
-static void
+static cairo_status_t
_cairo_ps_surface_emit_surface_pattern (cairo_ps_surface_t *surface,
cairo_surface_pattern_t *pattern)
{
double bbox_width, bbox_height;
double xstep, ystep;
cairo_matrix_t inverse = pattern->base.matrix;
+ cairo_status_t status;
- cairo_matrix_invert (&inverse);
+ status = cairo_matrix_invert (&inverse);
+ if (status)
+ return status;
if (_cairo_surface_is_meta (pattern->surface)) {
_cairo_output_stream_printf (surface->stream, "/MyPattern {\n");
- _cairo_meta_surface_replay (pattern->surface, &surface->base);
+ status = _cairo_meta_surface_replay (pattern->surface, &surface->base);
+ if (status)
+ return status;
bbox_width = surface->width;
bbox_height = surface->height;
xstep = surface->width;
@@ -1805,6 +1815,8 @@ _cairo_ps_surface_emit_surface_pattern (cairo_ps_surface_t *surface,
inverse.x0, inverse.y0);
_cairo_output_stream_printf (surface->stream,
"makepattern setpattern\n");
+
+ return CAIRO_STATUS_SUCCESS;
}
static void
@@ -1821,9 +1833,10 @@ _cairo_ps_surface_emit_radial_pattern (cairo_ps_surface_t *surface,
/* XXX: NYI */
}
-static void
+static cairo_status_t
_cairo_ps_surface_emit_pattern (cairo_ps_surface_t *surface, cairo_pattern_t *pattern)
{
+ cairo_status_t status = CAIRO_STATUS_SUCCESS;
/* FIXME: We should keep track of what pattern is currently set in
* the postscript file and only emit code if we're setting a
* different pattern. */
@@ -1834,7 +1847,7 @@ _cairo_ps_surface_emit_pattern (cairo_ps_surface_t *surface, cairo_pattern_t *pa
break;
case CAIRO_PATTERN_TYPE_SURFACE:
- _cairo_ps_surface_emit_surface_pattern (surface, (cairo_surface_pattern_t *) pattern);
+ status = _cairo_ps_surface_emit_surface_pattern (surface, (cairo_surface_pattern_t *) pattern);
break;
case CAIRO_PATTERN_TYPE_LINEAR:
@@ -1845,6 +1858,7 @@ _cairo_ps_surface_emit_pattern (cairo_ps_surface_t *surface, cairo_pattern_t *pa
_cairo_ps_surface_emit_radial_pattern (surface, (cairo_radial_pattern_t *) pattern);
break;
}
+ return status;
}
static cairo_int_status_t
@@ -1930,6 +1944,7 @@ _cairo_ps_surface_paint (void *abstract_surface,
cairo_ps_surface_t *surface = abstract_surface;
cairo_output_stream_t *stream = surface->stream;
cairo_rectangle_int16_t extents, pattern_extents;
+ cairo_status_t status;
if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
return _cairo_ps_surface_analyze_operation (surface, op, source);
@@ -1947,8 +1962,12 @@ _cairo_ps_surface_paint (void *abstract_surface,
_cairo_output_stream_printf (stream,
"%% _cairo_ps_surface_paint\n");
- _cairo_surface_get_extents (&surface->base, &extents);
- _cairo_pattern_get_extents (source, &pattern_extents);
+ status = _cairo_surface_get_extents (&surface->base, &extents);
+ if (status)
+ return status;
+ status = _cairo_pattern_get_extents (source, &pattern_extents);
+ if (status)
+ return status;
_cairo_rectangle_intersect (&extents, &pattern_extents);
_cairo_ps_surface_emit_pattern (surface, source);
@@ -2197,12 +2216,12 @@ _cairo_ps_surface_show_glyphs (void *abstract_surface,
int num_glyphs,
cairo_scaled_font_t *scaled_font)
{
+ cairo_status_t status;
cairo_ps_surface_t *surface = abstract_surface;
cairo_output_stream_t *stream = surface->stream;
unsigned int current_subset_id = -1;
unsigned int font_id;
cairo_ps_glyph_id_t *glyph_ids;
- cairo_status_t status;
unsigned int num_glyphs_unsigned, i, j, last, end;
cairo_bool_t vertical, horizontal;
cairo_output_stream_t *word_wrap;
@@ -2220,7 +2239,9 @@ _cairo_ps_surface_show_glyphs (void *abstract_surface,
num_glyphs_unsigned = num_glyphs;
- _cairo_ps_surface_emit_pattern (surface, source);
+ status = _cairo_ps_surface_emit_pattern (surface, source);
+ if (status)
+ return status;
glyph_ids = malloc (num_glyphs_unsigned*sizeof (cairo_ps_glyph_id_t));
if (glyph_ids == NULL)
return CAIRO_STATUS_NO_MEMORY;
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 963c060..407008d 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -397,15 +397,18 @@ _cairo_scaled_font_reset_cache (cairo_scaled_font_t *scaled_font)
max_glyphs_cached_per_font);
}
-void
+cairo_status_t
_cairo_scaled_font_set_metrics (cairo_scaled_font_t *scaled_font,
cairo_font_extents_t *fs_metrics)
{
double font_scale_x, font_scale_y;
+ cairo_status_t status;
- _cairo_matrix_compute_scale_factors (&scaled_font->font_matrix,
- &font_scale_x, &font_scale_y,
- /* XXX */ 1);
+ status = _cairo_matrix_compute_scale_factors (&scaled_font->font_matrix,
+ &font_scale_x, &font_scale_y,
+ /* XXX */ 1);
+ if (status)
+ return status;
/*
* The font responded in unscaled units, scale by the font
@@ -417,6 +420,8 @@ _cairo_scaled_font_set_metrics (cairo_scaled_font_t *scaled_font,
scaled_font->extents.height = fs_metrics->height * font_scale_y;
scaled_font->extents.max_x_advance = fs_metrics->max_x_advance * font_scale_x;
scaled_font->extents.max_y_advance = fs_metrics->max_y_advance * font_scale_y;
+
+ return status;
}
void
@@ -1197,6 +1202,7 @@ _trace_mask_to_path (cairo_image_surface_t *mask,
cairo_path_fixed_t *path)
{
cairo_image_surface_t *a1_mask;
+ cairo_status_t status = CAIRO_STATUS_SUCCESS;
unsigned char *row, *byte_ptr, byte;
int rows, cols, bytes_per_row;
int x, y, bit;
@@ -1218,28 +1224,39 @@ _trace_mask_to_path (cairo_image_surface_t *mask,
byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte_ptr);
for (bit = 7; bit >= 0 && x < a1_mask->width; bit--, x++) {
if (byte & (1 << bit)) {
- _cairo_path_fixed_move_to (path,
- _cairo_fixed_from_int (x + xoff),
- _cairo_fixed_from_int (y + yoff));
- _cairo_path_fixed_rel_line_to (path,
- _cairo_fixed_from_int (1),
- _cairo_fixed_from_int (0));
- _cairo_path_fixed_rel_line_to (path,
- _cairo_fixed_from_int (0),
- _cairo_fixed_from_int (1));
- _cairo_path_fixed_rel_line_to (path,
- _cairo_fixed_from_int (-1),
- _cairo_fixed_from_int (0));
- _cairo_path_fixed_close_path (path);
+ status = _cairo_path_fixed_move_to (path,
+ _cairo_fixed_from_int (x + xoff),
+ _cairo_fixed_from_int (y + yoff));
+ if (status)
+ goto BAIL;
+ status = _cairo_path_fixed_rel_line_to (path,
+ _cairo_fixed_from_int (1),
+ _cairo_fixed_from_int (0));
+ if (status)
+ goto BAIL;
+ status = _cairo_path_fixed_rel_line_to (path,
+ _cairo_fixed_from_int (0),
+ _cairo_fixed_from_int (1));
+ if (status)
+ goto BAIL;
+ status = _cairo_path_fixed_rel_line_to (path,
+ _cairo_fixed_from_int (-1),
+ _cairo_fixed_from_int (0));
+ if (status)
+ goto BAIL;
+ status = _cairo_path_fixed_close_path (path);
+ if (status)
+ goto BAIL;
}
}
}
}
+BAIL:
if (a1_mask != mask)
cairo_surface_destroy (&a1_mask->base);
- return CAIRO_STATUS_SUCCESS;
+ return status;
}
cairo_status_t
diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c
index 1a7d666..6a9fd1e 100644
--- a/src/cairo-surface-fallback.c
+++ b/src/cairo-surface-fallback.c
@@ -452,8 +452,11 @@ _composite_trap_region (cairo_clip_t *clip,
extents->width, extents->height);
/* Restore the original clip if we modified it temporarily. */
- if (num_rects >1)
- _cairo_surface_set_clip (dst, clip);
+ if (num_rects >1) {
+ cairo_status_t status2 = _cairo_surface_set_clip (dst, clip);
+ if (status == CAIRO_STATUS_SUCCESS)
+ status = status2;
+ }
if (clip_surface)
_cairo_pattern_fini (&mask.base);
@@ -979,7 +982,7 @@ _cairo_surface_fallback_snapshot (cairo_surface_t *surface)
_cairo_pattern_init_for_surface (&pattern.surface, &image->base);
- _cairo_surface_composite (CAIRO_OPERATOR_SOURCE,
+ status = _cairo_surface_composite (CAIRO_OPERATOR_SOURCE,
&pattern.base,
NULL,
snapshot,
@@ -993,6 +996,10 @@ _cairo_surface_fallback_snapshot (cairo_surface_t *surface)
_cairo_surface_release_source_image (surface,
image, &image_extra);
+ if (status != CAIRO_STATUS_SUCCESS) {
+ cairo_surface_destroy (snapshot);
+ return (cairo_surface_t *) &_cairo_surface_nil;
+ }
snapshot->device_transform = surface->device_transform;
snapshot->device_transform_inverse = surface->device_transform_inverse;
@@ -1158,13 +1165,14 @@ _cairo_surface_fallback_composite_trapezoids (cairo_operator_t op,
traps = offset_traps;
}
- _cairo_surface_composite_trapezoids (op, pattern,
- &state.image->base,
- antialias,
- src_x, src_y,
- dst_x - state.image_rect.x,
- dst_y - state.image_rect.y,
- width, height, traps, num_traps);
+ status = _cairo_surface_composite_trapezoids (op, pattern,
+ &state.image->base,
+ antialias,
+ src_x, src_y,
+ dst_x - state.image_rect.x,
+ dst_y - state.image_rect.y,
+ width, height,
+ traps, num_traps);
if (offset_traps)
free (offset_traps);
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 0da1557..d6cfcff 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -435,6 +435,7 @@ _cairo_svg_surface_store_page (cairo_svg_surface_t *surface)
{
unsigned int i;
cairo_svg_page_t page;
+ cairo_status_t status;
page.surface_id = surface->id;
page.clip_id = surface->base_clip;
@@ -447,7 +448,9 @@ _cairo_svg_surface_store_page (cairo_svg_surface_t *surface)
for (i = 0; i < page.clip_level; i++)
_cairo_output_stream_printf (page.xml_node, "</g>\n");
- _cairo_array_append (&surface->page_set, &page);
+ status = _cairo_array_append (&surface->page_set, &page);
+ if (status)
+ return NULL;
return _cairo_array_index (&surface->page_set, surface->page_set.num_elements - 1);
}
@@ -459,6 +462,8 @@ _cairo_svg_surface_copy_page (void *abstract_surface)
cairo_svg_page_t *page;
page = _cairo_svg_surface_store_page (surface);
+ if (page == NULL)
+ return CAIRO_STATUS_NO_MEMORY;
_cairo_memory_stream_copy (page->xml_node, surface->xml_node);
surface->clip_level = page->clip_level;
@@ -471,7 +476,8 @@ _cairo_svg_surface_show_page (void *abstract_surface)
{
cairo_svg_surface_t *surface = abstract_surface;
- _cairo_svg_surface_store_page (surface);
+ if (_cairo_svg_surface_store_page (surface) == NULL)
+ return CAIRO_STATUS_NO_MEMORY;
return CAIRO_STATUS_SUCCESS;
}
@@ -777,6 +783,7 @@ static cairo_status_t
_cairo_svg_surface_finish (void *abstract_surface)
{
cairo_status_t status;
+ cairo_status_t status2;
cairo_svg_surface_t *surface = abstract_surface;
cairo_svg_document_t *document = surface->document;
cairo_svg_page_t *page;
@@ -787,11 +794,15 @@ _cairo_svg_surface_finish (void *abstract_surface)
else
status = CAIRO_STATUS_SUCCESS;
- _cairo_output_stream_destroy (surface->xml_node);
+ status2 = _cairo_output_stream_destroy (surface->xml_node);
+ if (status == CAIRO_STATUS_SUCCESS)
+ status = status2;
for (i = 0; i < surface->page_set.num_elements; i++) {
page = _cairo_array_index (&surface->page_set, i);
- _cairo_output_stream_destroy (page->xml_node);
+ status2 = _cairo_output_stream_destroy (page->xml_node);
+ if (status == CAIRO_STATUS_SUCCESS)
+ status = status2;
}
_cairo_array_fini (&surface->page_set);
@@ -941,7 +952,9 @@ _cairo_svg_surface_emit_composite_image_pattern (cairo_output_stream_t *outp
return status;
p2u = pattern->base.matrix;
- cairo_matrix_invert (&p2u);
+ status = cairo_matrix_invert (&p2u);
+ if (status)
+ return status;
if (pattern_id != invalid_pattern_id) {
_cairo_output_stream_printf (output,
@@ -1074,6 +1087,7 @@ _cairo_svg_surface_emit_composite_meta_pattern (cairo_output_stream_t *output,
{
cairo_svg_document_t *document = surface->document;
cairo_meta_surface_t *meta_surface;
+ cairo_status_t status;
cairo_matrix_t p2u;
int id;
@@ -1082,7 +1096,9 @@ _cairo_svg_surface_emit_composite_meta_pattern (cairo_output_stream_t *output,
id = _cairo_svg_surface_emit_meta_surface (document, meta_surface);
p2u = pattern->base.matrix;
- cairo_matrix_invert (&p2u);
+ status = cairo_matrix_invert (&p2u);
+ if (status)
+ return status;
if (pattern_id != invalid_pattern_id) {
_cairo_output_stream_printf (output,
@@ -1406,13 +1422,14 @@ _cairo_svg_surface_emit_linear_pattern (cairo_svg_surface_t *surface,
document->linear_pattern_id++;
}
-static void
+static cairo_status_t
_cairo_svg_surface_emit_radial_pattern (cairo_svg_surface_t *surface,
cairo_radial_pattern_t *pattern,
cairo_output_stream_t *style,
cairo_bool_t is_stroke)
{
cairo_svg_document_t *document = surface->document;
+ cairo_status_t status;
cairo_matrix_t p2u;
cairo_extend_t extend;
double x0, y0, x1, y1, r0, r1;
@@ -1440,7 +1457,9 @@ _cairo_svg_surface_emit_radial_pattern (cairo_svg_surface_t *surface,
r1 = _cairo_fixed_to_double (c1->radius);
p2u = pattern->base.base.matrix;
- cairo_matrix_invert (&p2u);
+ status = cairo_matrix_invert (&p2u);
+ if (status)
+ return status;
if (pattern->gradient.c1.radius == pattern->gradient.c2.radius) {
_cairo_output_stream_printf (document->xml_node_defs,
@@ -1571,12 +1590,15 @@ _cairo_svg_surface_emit_radial_pattern (cairo_svg_surface_t *surface,
document->radial_pattern_id);
document->radial_pattern_id++;
+
+ return status;
}
-static void
+cairo_static cairo_status_t
_cairo_svg_surface_emit_pattern (cairo_svg_surface_t *surface, cairo_pattern_t *pattern,
cairo_output_stream_t *output, cairo_bool_t is_stroke)
{
+ cairo_status_t status = CAIRO_STATUS_SUCCESS;
switch (pattern->type) {
case CAIRO_PATTERN_TYPE_SOLID:
_cairo_svg_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern, output, is_stroke);
@@ -1591,9 +1613,10 @@ _cairo_svg_surface_emit_pattern (cairo_svg_surface_t *surface, cairo_pattern_t *
break;
case CAIRO_PATTERN_TYPE_RADIAL:
- _cairo_svg_surface_emit_radial_pattern (surface, (cairo_radial_pattern_t *) pattern, output, is_stroke);
+ status = _cairo_svg_surface_emit_radial_pattern (surface, (cairo_radial_pattern_t *) pattern, output, is_stroke);
break;
}
+ return status;
}
static cairo_int_status_t
@@ -1619,7 +1642,9 @@ _cairo_svg_surface_fill (void *abstract_surface,
fill_rule == CAIRO_FILL_RULE_EVEN_ODD ?
"evenodd" : "nonzero");
_cairo_svg_surface_emit_operator (surface->xml_node, surface, op);
- _cairo_svg_surface_emit_pattern (surface, source, surface->xml_node, FALSE);
+ status = _cairo_svg_surface_emit_pattern (surface, source, surface->xml_node, FALSE);
+ if (status)
+ return status;
_cairo_output_stream_printf (surface->xml_node, "\" ");
status = _cairo_svg_surface_emit_path (surface->xml_node, path, NULL);
diff --git a/src/cairo-traps.c b/src/cairo-traps.c
index 65075c2..ec1d78d 100644
--- a/src/cairo-traps.c
+++ b/src/cairo-traps.c
@@ -385,6 +385,7 @@ _cairo_traps_tessellate_convex_quad (cairo_traps_t *traps, cairo_point_t q[4])
b_left_of_d = (_cairo_slope_compare (&ab, &ad) > 0);
+ /* ignore the status returns until the end */
if (q[c].y <= q[d].y) {
if (b_left_of_d) {
/* Y-sort is abcd and b is left of d, (slope(ab) > slope (ad))
diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index a99aed7..a013396 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -320,16 +320,20 @@ cairo_truetype_font_align_output (cairo_truetype_font_t *font)
return aligned;
}
-static void
+static cairo_status_t
cairo_truetype_font_check_boundary (cairo_truetype_font_t *font,
unsigned long boundary)
{
if (boundary - font->last_offset > SFNT_STRING_MAX_LENGTH)
{
- _cairo_array_append(&font->string_offsets, &font->last_boundary);
+ cairo_status_t status;
+ status = _cairo_array_append(&font->string_offsets, &font->last_boundary);
+ if (status)
+ return status;
font->last_offset = font->last_boundary;
}
font->last_boundary = boundary;
+ return CAIRO_STATUS_SUCCESS;
}
static int
@@ -487,7 +491,9 @@ cairo_truetype_font_write_glyf_table (cairo_truetype_font_t *font,
size = end - begin;
next = cairo_truetype_font_align_output (font);
- cairo_truetype_font_check_boundary (font, next);
+ status = cairo_truetype_font_check_boundary (font, next);
+ if (status)
+ break;
font->glyphs[i].location = next - start_offset;
status = cairo_truetype_font_allocate_write_buffer (font, size, &buffer);
@@ -793,7 +799,8 @@ cairo_truetype_font_generate (cairo_truetype_font_t *font,
next = cairo_truetype_font_align_output (font);
cairo_truetype_font_update_entry (font, truetype_tables[i].pos, truetype_tables[i].tag,
start, end);
- cairo_truetype_font_check_boundary (font, next);
+ if (cairo_truetype_font_check_boundary (font, next))
+ goto fail;
start = next;
}
diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index a183b28..5502787 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -464,10 +464,11 @@ fail:
return status;
}
-static void
+static cairo_status_t
cairo_type1_font_write_header (cairo_type1_font_t *font,
const char *name)
{
+ cairo_status_t status;
cairo_matrix_t matrix;
unsigned int i;
const char spaces[50] = " ";
@@ -475,7 +476,9 @@ cairo_type1_font_write_header (cairo_type1_font_t *font,
matrix = font->type1_scaled_font->scale;
matrix.xy = -matrix.xy;
matrix.yy = -matrix.yy;
- cairo_matrix_invert (&matrix);
+ status = cairo_matrix_invert (&matrix);
+ if (status)
+ return status;
_cairo_output_stream_printf (font->output,
"%%!FontType1-1.1 %s 1.0\n"
@@ -512,6 +515,8 @@ cairo_type1_font_write_header (cairo_type1_font_t *font,
"readonly def\n"
"currentdict end\n"
"currentfile eexec\n");
+
+ return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t
@@ -558,6 +563,7 @@ cairo_type1_font_write_private_dict (cairo_type1_font_t *font,
const char *name)
{
cairo_int_status_t status;
+ cairo_status_t status2;
cairo_output_stream_t *encrypted_output;
font->eexec_key = CAIRO_TYPE1_PRIVATE_DICT_KEY;
@@ -600,7 +606,9 @@ cairo_type1_font_write_private_dict (cairo_type1_font_t *font,
if (status == CAIRO_STATUS_SUCCESS)
status = _cairo_output_stream_get_status (encrypted_output);
fail:
- _cairo_output_stream_destroy (encrypted_output);
+ status2 = _cairo_output_stream_destroy (encrypted_output);
+ if (status == CAIRO_STATUS_SUCCESS)
+ status = status2;
return status;
}
@@ -634,7 +642,9 @@ cairo_type1_font_write (cairo_type1_font_t *font,
{
cairo_int_status_t status;
- cairo_type1_font_write_header (font, name);
+ status = cairo_type1_font_write_header (font, name);
+ if (status)
+ return status;
font->header_size = _cairo_output_stream_get_position (font->output);
status = cairo_type1_font_write_private_dict (font, name);
@@ -672,14 +682,16 @@ cairo_type1_font_generate (cairo_type1_font_t *font, const char *name)
return CAIRO_STATUS_SUCCESS;
}
-static void
+cairo_static cairo_status_t
cairo_type1_font_destroy (cairo_type1_font_t *font)
{
+ cairo_status_t status;
free (font->widths);
cairo_scaled_font_destroy (font->type1_scaled_font);
_cairo_array_fini (&font->contents);
- _cairo_output_stream_destroy (font->output);
+ status = _cairo_output_stream_destroy (font->output);
free (font);
+ return status;
}
static cairo_status_t
@@ -745,9 +757,9 @@ _cairo_type1_fallback_init_internal (cairo_type1_subset_t *type1_subset,
type1_subset->data_length = font->data_size;
type1_subset->trailer_length = font->trailer_size;
- cairo_type1_font_destroy (font);
- return CAIRO_STATUS_SUCCESS;
+ return cairo_type1_font_destroy (font);
+ /* error path, ignore further errors */
fail3:
free (type1_subset->widths);
fail2:
diff --git a/src/cairo-xlib-private.h b/src/cairo-xlib-private.h
index 8ba46a2..9ecf5fe 100644
--- a/src/cairo-xlib-private.h
+++ b/src/cairo-xlib-private.h
@@ -63,7 +63,7 @@ _cairo_xlib_screen_info_get (Display *display, Screen *screen);
cairo_private cairo_bool_t
_cairo_xlib_add_close_display_hook (Display *display, void (*func) (Display *, void *), void *data, void *key);
-cairo_private void
+cairo_private_no_warn void
_cairo_xlib_remove_close_display_hook (Display *display, void *key);
#if CAIRO_HAS_XLIB_XRENDER_SURFACE
diff --git a/src/cairo.c b/src/cairo.c
index 21303de..1c5eafc 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -189,6 +189,7 @@ cairo_t *
cairo_create (cairo_surface_t *target)
{
cairo_t *cr;
+ cairo_status_t status;
cr = malloc (sizeof (cairo_t));
if (cr == NULL)
@@ -201,12 +202,16 @@ cairo_create (cairo_surface_t *target)
_cairo_user_data_array_init (&cr->user_data);
cr->gstate = cr->gstate_tail;
- _cairo_gstate_init (cr->gstate, target);
+ status = _cairo_gstate_init (cr->gstate, target);
_cairo_path_fixed_init (cr->path);
if (target == NULL) {
- _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
+ /* override internal errors */
+ status = CAIRO_STATUS_NULL_POINTER;
+ }
+ if (status) {
+ _cairo_set_error (cr, status);
}
return cr;
@@ -491,7 +496,9 @@ cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
cairo_surface_t *group_surface = NULL;
/* Get the extents that we'll use in creating our new group surface */
- _cairo_surface_get_extents (_cairo_gstate_get_target (cr->gstate), &extents);
+ status = _cairo_surface_get_extents (_cairo_gstate_get_target (cr->gstate), &extents);
+ if (status != CAIRO_STATUS_SUCCESS)
+ goto bail;
status = _cairo_clip_intersect_to_rectangle (_cairo_gstate_get_clip (cr->gstate), &extents);
if (status != CAIRO_STATUS_SUCCESS)
goto bail;
@@ -518,7 +525,7 @@ cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
if (cr->status)
goto bail;
- _cairo_gstate_redirect_target (cr->gstate, group_surface);
+ status = _cairo_gstate_redirect_target (cr->gstate, group_surface);
bail:
cairo_surface_destroy (group_surface);
@@ -1624,17 +1631,20 @@ void
cairo_rel_move_to (cairo_t *cr, double dx, double dy)
{
cairo_fixed_t dx_fixed, dy_fixed;
+ cairo_status_t status;
if (cr->status)
return;
- _cairo_gstate_user_to_device_distance (cr->gstate, &dx, &dy);
- dx_fixed = _cairo_fixed_from_double (dx);
- dy_fixed = _cairo_fixed_from_double (dy);
+ status = _cairo_gstate_user_to_device_distance (cr->gstate, &dx, &dy);
+ if (status == CAIRO_STATUS_SUCCESS) {
+ dx_fixed = _cairo_fixed_from_double (dx);
+ dy_fixed = _cairo_fixed_from_double (dy);
- cr->status = _cairo_path_fixed_rel_move_to (cr->path, dx_fixed, dy_fixed);
- if (cr->status)
- _cairo_set_error (cr, cr->status);
+ status = _cairo_path_fixed_rel_move_to (cr->path, dx_fixed, dy_fixed);
+ }
+ if (status)
+ _cairo_set_error (cr, status);
}
/**
@@ -1659,17 +1669,20 @@ void
cairo_rel_line_to (cairo_t *cr, double dx, double dy)
{
cairo_fixed_t dx_fixed, dy_fixed;
+ cairo_status_t status;
if (cr->status)
return;
- _cairo_gstate_user_to_device_distance (cr->gstate, &dx, &dy);
- dx_fixed = _cairo_fixed_from_double (dx);
- dy_fixed = _cairo_fixed_from_double (dy);
+ status = _cairo_gstate_user_to_device_distance (cr->gstate, &dx, &dy);
+ if (status == CAIRO_STATUS_SUCCESS) {
+ dx_fixed = _cairo_fixed_from_double (dx);
+ dy_fixed = _cairo_fixed_from_double (dy);
- cr->status = _cairo_path_fixed_rel_line_to (cr->path, dx_fixed, dy_fixed);
- if (cr->status)
- _cairo_set_error (cr, cr->status);
+ status = _cairo_path_fixed_rel_line_to (cr->path, dx_fixed, dy_fixed);
+ }
+ if (status)
+ _cairo_set_error (cr, status);
}
slim_hidden_def(cairo_rel_line_to);
@@ -1708,13 +1721,20 @@ cairo_rel_curve_to (cairo_t *cr,
cairo_fixed_t dx1_fixed, dy1_fixed;
cairo_fixed_t dx2_fixed, dy2_fixed;
cairo_fixed_t dx3_fixed, dy3_fixed;
+ cairo_status_t status;
if (cr->status)
return;
- _cairo_gstate_user_to_device_distance (cr->gstate, &dx1, &dy1);
- _cairo_gstate_user_to_device_distance (cr->gstate, &dx2, &dy2);
- _cairo_gstate_user_to_device_distance (cr->gstate, &dx3, &dy3);
+ status = _cairo_gstate_user_to_device_distance (cr->gstate, &dx1, &dy1);
+ if (status)
+ goto BAIL;
+ status = _cairo_gstate_user_to_device_distance (cr->gstate, &dx2, &dy2);
+ if (status)
+ goto BAIL;
+ status = _cairo_gstate_user_to_device_distance (cr->gstate, &dx3, &dy3);
+ if (status)
+ goto BAIL;
dx1_fixed = _cairo_fixed_from_double (dx1);
dy1_fixed = _cairo_fixed_from_double (dy1);
@@ -1725,11 +1745,12 @@ cairo_rel_curve_to (cairo_t *cr,
dx3_fixed = _cairo_fixed_from_double (dx3);
dy3_fixed = _cairo_fixed_from_double (dy3);
- cr->status = _cairo_path_fixed_rel_curve_to (cr->path,
- dx1_fixed, dy1_fixed,
- dx2_fixed, dy2_fixed,
- dx3_fixed, dy3_fixed);
- if (cr->status)
+ status = _cairo_path_fixed_rel_curve_to (cr->path,
+ dx1_fixed, dy1_fixed,
+ dx2_fixed, dy2_fixed,
+ dx3_fixed, dy3_fixed);
+BAIL:
+ if (status)
_cairo_set_error (cr, cr->status);
}
diff --git a/src/cairoint.h b/src/cairoint.h
index 579f021..9c0c939 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1262,7 +1262,7 @@ _cairo_gstate_destroy (cairo_gstate_t *gstate);
cairo_private cairo_bool_t
_cairo_gstate_is_redirected (cairo_gstate_t *gstate);
-cairo_private_no_warn void
+cairo_private cairo_status_t
_cairo_gstate_redirect_target (cairo_gstate_t *gstate, cairo_surface_t *child);
cairo_private cairo_surface_t *
@@ -1744,7 +1744,7 @@ _cairo_scaled_font_init (cairo_scaled_font_t *scaled_font,
const cairo_font_options_t *options,
const cairo_scaled_font_backend_t *backend);
-cairo_private_no_warn void
+cairo_private cairo_status_t
_cairo_scaled_font_set_metrics (cairo_scaled_font_t *scaled_font,
cairo_font_extents_t *fs_metrics);
@@ -2186,7 +2186,7 @@ _cairo_pen_init_empty (cairo_pen_t *pen);
cairo_private cairo_status_t
_cairo_pen_init_copy (cairo_pen_t *pen, cairo_pen_t *other);
-cairo_private_no_warn void
+cairo_private cairo_status_t
_cairo_pen_fini (cairo_pen_t *pen);
cairo_private cairo_status_t
diff --git a/test/buffer-diff.c b/test/buffer-diff.c
index d111b23..a77a145 100644
--- a/test/buffer-diff.c
+++ b/test/buffer-diff.c
@@ -275,7 +275,7 @@ image_diff_core (const char *filename_a,
buffer_diff_result_t *result,
cairo_bool_t flatten)
{
- cairo_status_t status;
+ cairo_status_t status = CAIRO_STATUS_SUCCESS;
unsigned int width_a, height_a, stride_a;
unsigned int width_b, height_b, stride_b;
cairo_surface_t *surface_a, *surface_b, *surface_diff;
@@ -347,7 +347,7 @@ image_diff_core (const char *filename_a,
else
png_file = stdout;
- cairo_surface_write_to_png_stream (surface_diff, stdio_write_func, png_file);
+ status = cairo_surface_write_to_png_stream (surface_diff, stdio_write_func, png_file);
if (png_file != stdout)
fclose (png_file);
@@ -360,7 +360,7 @@ image_diff_core (const char *filename_a,
cairo_surface_destroy (surface_b);
cairo_surface_destroy (surface_diff);
- return CAIRO_STATUS_SUCCESS;
+ return status;
}
cairo_status_t
--
1.4.4.2
More information about the cairo
mailing list