diff options
author | Carl Worth <cworth@cworth.org> | 2007-04-11 13:15:57 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2007-04-11 13:15:57 -0700 |
commit | e36794ad34282a4d671d7cc5527e9c650c2736fe (patch) | |
tree | cac8402c5f9728e3a2fff2a421796f07bd0b978d | |
parent | b6924722b8c8e5f4356d3c8ba438a702ffb8a5ed (diff) | |
parent | b745126a04c126acc695e8abb6372c1890b03f07 (diff) |
Merge branch 'warn-unused-result' into cairo
56 files changed, 1940 insertions, 1142 deletions
diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c index 6a1acb88b..109f75b7f 100644 --- a/boilerplate/cairo-boilerplate.c +++ b/boilerplate/cairo-boilerplate.c @@ -120,6 +120,24 @@ create_image_surface (const char *name, return cairo_image_surface_create (format, width, height); } +static void +xcairo_surface_set_user_data (cairo_surface_t *surface, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy) +{ + cairo_status_t status; + + status = cairo_surface_set_user_data (surface, + key, user_data, + destroy); + if (status) { + CAIRO_BOILERPLATE_LOG ("Error: %s. Exiting\n", + cairo_status_to_string (status)); + exit (1); + } +} + #ifdef CAIRO_HAS_TEST_SURFACES #include "test-fallback-surface.h" @@ -186,8 +204,8 @@ create_test_paginated_surface (const char *name, tpc->height, tpc->stride); - cairo_surface_set_user_data (surface, &test_paginated_closure_key, - tpc, NULL); + xcairo_surface_set_user_data (surface, &test_paginated_closure_key, + tpc, NULL); return surface; } @@ -210,6 +228,7 @@ test_paginated_write_to_png (cairo_surface_t *surface, cairo_surface_t *image; cairo_format_t format; test_paginated_closure_t *tpc; + cairo_status_t status; /* show page first. the automatic show_page is too late for us */ /* XXX use cairo_surface_show_page() when that's added */ @@ -238,7 +257,13 @@ test_paginated_write_to_png (cairo_surface_t *surface, tpc->height, tpc->stride); - cairo_surface_write_to_png (image, filename); + status = cairo_surface_write_to_png (image, filename); + if (status) { + CAIRO_BOILERPLATE_LOG ("Error writing %s: %s. Exiting\n", + filename, + cairo_status_to_string (status)); + exit (1); + } cairo_surface_destroy (image); @@ -1062,7 +1087,15 @@ 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_STATUS_SUCCESS) { + cairo_surface_destroy (surface); + free (ptc->filename); + free (ptc); + return NULL; + } return surface; } @@ -1171,7 +1204,7 @@ create_pdf_surface (const char *name, ptc->target = NULL; } - cairo_surface_set_user_data (surface, &pdf_closure_key, ptc, NULL); + xcairo_surface_set_user_data (surface, &pdf_closure_key, ptc, NULL); return surface; } @@ -1277,7 +1310,7 @@ create_svg_surface (const char *name, ptc->target = NULL; } - cairo_surface_set_user_data (surface, &svg_closure_key, ptc, NULL); + xcairo_surface_set_user_data (surface, &svg_closure_key, ptc, NULL); return surface; } diff --git a/configure.in b/configure.in index e625fc518..f267c22c8 100644 --- a/configure.in +++ b/configure.in @@ -436,7 +436,7 @@ FREETYPE_MIN_VERSION=8.0.2 CAIRO_BACKEND_ENABLE(ft, FreeType font, freetype, FT_FONT, auto, [ ft_REQUIRES="fontconfig" PKG_CHECK_MODULES(FONTCONFIG, $ft_REQUIRES, - [_CHECK_FUNCS_WITH_FLAGS(FcFini, $ft_CFLAGS, $ft_LIBS)], + [_CHECK_FUNCS_WITH_FLAGS(FcFini, [$FONTCONFIG_CFLAGS], [$FONTCONFIG_LIBS])], [AC_MSG_RESULT(no); use_ft="no (requires fontconfig"]) if test "x$use_ft" = "xyes"; then @@ -623,7 +623,8 @@ MAYBE_WARN="-Wall -Wextra \ -Wpacked -Wswitch-enum -Wmissing-format-attribute \ -Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \ -Wdeclaration-after-statement -Wold-style-definition \ --Wno-missing-field-initializers -Wno-unused-parameter" +-Wno-missing-field-initializers -Wno-unused-parameter \ +-Wno-attributes" # invalidate cached value if MAYBE_WARN has changed @@ -844,9 +845,19 @@ AC_CONFIG_COMMANDS([src/cairo-features.h], # define CAIRO_END_DECLS #endif +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +#define CAIRO_WARN_UNUSED_RESULT \ + __attribute__((__warn_unused_result__)) +#else +#define CAIRO_WARN_UNUSED_RESULT +#endif /* __GNUC__ */ + #ifndef cairo_public # define cairo_public #endif +#ifndef cairo_public_warn +# define cairo_public_warn CAIRO_WARN_UNUSED_RESULT +#endif #define CAIRO_VERSION_MAJOR $CAIRO_VERSION_MAJOR #define CAIRO_VERSION_MINOR $CAIRO_VERSION_MINOR diff --git a/perf/text.c b/perf/text.c index de5e0cd8b..efe7d913e 100644 --- a/perf/text.c +++ b/perf/text.c @@ -40,14 +40,14 @@ do_text (cairo_t *cr, int width, int height) cairo_move_to (cr, 0, i * 10); cairo_show_text (cr, text + i); cairo_get_current_point (cr, &x, &y); - while (x < width) { + while (x < width && cairo_status (cr) == CAIRO_STATUS_SUCCESS) { cairo_show_text (cr, text); cairo_get_current_point (cr, &x, &y); } i++; if (i >= len) i = 0; - } while (y < height); + } while (y < height && cairo_status (cr) == CAIRO_STATUS_SUCCESS); cairo_perf_timer_stop (); diff --git a/pixman/configure.in b/pixman/configure.in index c9cdae8f5..4cbb5ba5f 100644 --- a/pixman/configure.in +++ b/pixman/configure.in @@ -45,7 +45,8 @@ WARN_CFLAGS="" if test "x$GCC" = "xyes"; then WARN_CFLAGS="-Wall -Wpointer-arith -Wstrict-prototypes \ -Wmissing-prototypes -Wmissing-declarations \ - -Wnested-externs -fno-strict-aliasing" + -Wnested-externs -fno-strict-aliasing \ + -Wno-attributes" fi AC_SUBST(WARN_CFLAGS) diff --git a/pixman/src/fbmmx.c b/pixman/src/fbmmx.c index 0287e79e9..e11f8499d 100644 --- a/pixman/src/fbmmx.c +++ b/pixman/src/fbmmx.c @@ -1658,6 +1658,102 @@ fbCompositeSolidMask_nx8x8888mmx (pixman_operator_t op, _mm_empty(); } +static void +fbSolidFillmmx (FbPixels *pDraw, + int x, + int y, + int width, + int height, + FbBits xor) +{ + FbStride stride; + int bpp; + ullong fill; + __m64 vfill; + CARD32 byte_width; + CARD8 *byte_line; + FbBits *bits; + int xoff, yoff; + + CHECKPOINT(); + + fbGetDrawable(pDraw, bits, stride, bpp, xoff, yoff); + + assert (bpp == 32 || (xor >> 16 == (xor & 0xffff))); + assert (bpp == 16 || bpp == 32); + + if (bpp == 16) + { + stride = stride * sizeof (FbBits) / 2; + byte_line = (CARD8 *)(((CARD16 *)bits) + stride * (y + yoff) + (x + xoff)); + byte_width = 2 * width; + stride *= 2; + } + else + { + stride = stride * sizeof (FbBits) / 4; + byte_line = (CARD8 *)(((CARD32 *)bits) + stride * (y + yoff) + (x + xoff)); + byte_width = 4 * width; + stride *= 4; + } + + fill = ((ullong)xor << 32) | xor; + vfill = M64(fill); + + while (height--) + { + unsigned int w; + CARD8 *d = byte_line; + byte_line += stride; + w = byte_width; + + while (w >= 2 && ((unsigned long)d & 3)) + { + *(CARD16 *)d = xor; + w -= 2; + d += 2; + } + + while (w >= 4 && ((unsigned long)d & 7)) + { + *(CARD32 *)d = xor; + + w -= 4; + d += 4; + } + + while (w >= 64) + { + *(__m64*) (d + 0) = vfill; + *(__m64*) (d + 8) = vfill; + *(__m64*) (d + 16) = vfill; + *(__m64*) (d + 24) = vfill; + *(__m64*) (d + 32) = vfill; + *(__m64*) (d + 40) = vfill; + *(__m64*) (d + 48) = vfill; + *(__m64*) (d + 56) = vfill; + + w -= 64; + d += 64; + } + while (w >= 4) + { + *(CARD32 *)d = xor; + + w -= 4; + d += 4; + } + if (w >= 2) + { + *(CARD16 *)d = xor; + w -= 2; + d += 2; + } + } + + _mm_empty(); +} + void fbCompositeSolidMaskSrc_nx8x8888mmx (pixman_operator_t op, PicturePtr pSrc, @@ -1687,8 +1783,8 @@ fbCompositeSolidMaskSrc_nx8x8888mmx (pixman_operator_t op, srca = src >> 24; if (srca == 0) { - if (fbSolidFillmmx (pDst->pDrawable, xDst, yDst, width, height, 0)) - return; + fbSolidFillmmx (pDst->pDrawable, xDst, yDst, width, height, 0); + return; } srcsrc = (ullong)src << 32 | src; @@ -2592,107 +2688,7 @@ fbCompositeSrcAdd_8888x8888mmx (pixman_operator_t op, _mm_empty(); } -Bool -fbSolidFillmmx (FbPixels *pDraw, - int x, - int y, - int width, - int height, - FbBits xor) -{ - FbStride stride; - int bpp; - ullong fill; - __m64 vfill; - CARD32 byte_width; - CARD8 *byte_line; - FbBits *bits; - int xoff, yoff; - - CHECKPOINT(); - - fbGetDrawable(pDraw, bits, stride, bpp, xoff, yoff); - - if (bpp == 16 && (xor >> 16 != (xor & 0xffff))) - return FALSE; - - if (bpp != 16 && bpp != 32) - return FALSE; - - if (bpp == 16) - { - stride = stride * sizeof (FbBits) / 2; - byte_line = (CARD8 *)(((CARD16 *)bits) + stride * (y + yoff) + (x + xoff)); - byte_width = 2 * width; - stride *= 2; - } - else - { - stride = stride * sizeof (FbBits) / 4; - byte_line = (CARD8 *)(((CARD32 *)bits) + stride * (y + yoff) + (x + xoff)); - byte_width = 4 * width; - stride *= 4; - } - - fill = ((ullong)xor << 32) | xor; - vfill = M64(fill); - - while (height--) - { - unsigned int w; - CARD8 *d = byte_line; - byte_line += stride; - w = byte_width; - - while (w >= 2 && ((unsigned long)d & 3)) - { - *(CARD16 *)d = xor; - w -= 2; - d += 2; - } - - while (w >= 4 && ((unsigned long)d & 7)) - { - *(CARD32 *)d = xor; - - w -= 4; - d += 4; - } - - while (w >= 64) - { - *(__m64*) (d + 0) = vfill; - *(__m64*) (d + 8) = vfill; - *(__m64*) (d + 16) = vfill; - *(__m64*) (d + 24) = vfill; - *(__m64*) (d + 32) = vfill; - *(__m64*) (d + 40) = vfill; - *(__m64*) (d + 48) = vfill; - *(__m64*) (d + 56) = vfill; - - w -= 64; - d += 64; - } - while (w >= 4) - { - *(CARD32 *)d = xor; - - w -= 4; - d += 4; - } - if (w >= 2) - { - *(CARD16 *)d = xor; - w -= 2; - d += 2; - } - } - - _mm_empty(); - return TRUE; -} - -Bool +static void fbCopyAreammx (FbPixels *pSrc, FbPixels *pDst, int src_x, @@ -2721,16 +2717,8 @@ fbCopyAreammx (FbPixels *pSrc, fbGetDrawable(pSrc, src_bits, src_stride, src_bpp, src_xoff, src_yoff); fbGetDrawable(pDst, dst_bits, dst_stride, dst_bpp, dst_xoff, dst_yoff); - if (src_bpp != 16 && src_bpp != 32) - return FALSE; - - if (dst_bpp != 16 && dst_bpp != 32) - return FALSE; - - if (src_bpp != dst_bpp) - { - return FALSE; - } + assert (src_bpp == dst_bpp); + assert (src_bpp == 16 || src_bpp == 32); if (src_bpp == 16) { @@ -2811,7 +2799,6 @@ fbCopyAreammx (FbPixels *pSrc, } _mm_empty(); - return TRUE; } void diff --git a/pixman/src/fbmmx.h b/pixman/src/fbmmx.h index 054ac0b73..9c20cd6a7 100644 --- a/pixman/src/fbmmx.h +++ b/pixman/src/fbmmx.h @@ -283,16 +283,6 @@ void fbCompositeSrc_8888x8888mmx (pixman_operator_t op, CARD16 width, CARD16 height); pixman_private -Bool fbCopyAreammx (FbPixels *pSrc, - FbPixels *pDst, - int src_x, - int src_y, - int dst_x, - int dst_y, - int width, - int height); - -pixman_private void fbCompositeCopyAreammx (pixman_operator_t op, PicturePtr pSrc, PicturePtr pMask, @@ -305,13 +295,4 @@ void fbCompositeCopyAreammx (pixman_operator_t op, INT16 yDst, CARD16 width, CARD16 height); - -pixman_private -Bool fbSolidFillmmx (FbPixels *pDraw, - int x, - int y, - int width, - int height, - FbBits xor); - #endif /* USE_MMX */ diff --git a/pixman/src/icimage.c b/pixman/src/icimage.c index e01146181..34d68ef0b 100644 --- a/pixman/src/icimage.c +++ b/pixman/src/icimage.c @@ -509,7 +509,11 @@ pixman_image_set_clip_region (pixman_image_t *image, if (region) { pixman_region_init (&image->clientClip); - pixman_region_copy (&image->clientClip, region); + if (pixman_region_copy (&image->clientClip, region) != + PIXMAN_REGION_STATUS_SUCCESS) { + pixman_region_fini (&image->clientClip); + return 1; + } image->clientClipType = CT_REGION; } @@ -530,9 +534,14 @@ pixman_image_set_clip_region (pixman_image_t *image, pixman_region_translate (&image->compositeClip, - image->clipOrigin.x, - image->clipOrigin.y); - pixman_region_intersect (&image->compositeClip, + if (pixman_region_intersect (&image->compositeClip, &image->compositeClip, - region); + region) != PIXMAN_REGION_STATUS_SUCCESS) { + pixman_image_destroyClip (image); + pixman_region_fini (&image->compositeClip); + image->hasCompositeClip = 0; + return 1; + } pixman_region_translate (&image->compositeClip, image->clipOrigin.x, image->clipOrigin.y); @@ -549,6 +558,7 @@ FbClipImageReg (pixman_region16_t *region, int dx, int dy) { + int ret = 1; if (pixman_region_num_rects (region) == 1 && pixman_region_num_rects (clip) == 1) { @@ -572,11 +582,14 @@ FbClipImageReg (pixman_region16_t *region, } else { + pixman_region_status_t status; + pixman_region_translate (region, dx, dy); - pixman_region_intersect (region, clip, region); + status = pixman_region_intersect (region, clip, region); + ret = status == PIXMAN_REGION_STATUS_SUCCESS; pixman_region_translate (region, -dx, -dy); } - return 1; + return ret; } static inline int @@ -591,19 +604,25 @@ FbClipImageSrc (pixman_region16_t *region, /* XXX davidr hates this, wants to never use source-based clipping */ if (image->repeat != PIXMAN_REPEAT_NONE || image->pSourcePict) { + int ret = 1; /* XXX no source clipping */ if (image->compositeClipSource && image->clientClipType != CT_NONE) { + pixman_region_status_t status; + pixman_region_translate (region, dx - image->clipOrigin.x, dy - image->clipOrigin.y); - pixman_region_intersect (region, &image->clientClip, region); + status = pixman_region_intersect (region, + &image->clientClip, + region); + ret = status == PIXMAN_REGION_STATUS_SUCCESS; pixman_region_translate (region, - (dx - image->clipOrigin.x), - (dy - image->clipOrigin.y)); } - return 1; + return ret; } else { pixman_region16_t *clip; diff --git a/pixman/src/icrect.c b/pixman/src/icrect.c index a6c080c40..982c11463 100644 --- a/pixman/src/icrect.c +++ b/pixman/src/icrect.c @@ -180,7 +180,7 @@ pixman_fill_rect_general (pixman_image_t *dst, } } -static void +static int pixman_color_rects (pixman_image_t *dst, pixman_image_t *clipPict, pixman_color_t *color, @@ -195,6 +195,7 @@ pixman_color_rects (pixman_image_t *dst, pixman_box16_t *clipped_rects; int i, n_clipped_rects; FillFunc func; + pixman_region_status_t status; pixman_color_to_pixel (&dst->image_format, color, @@ -208,16 +209,29 @@ pixman_color_rects (pixman_image_t *dst, dst->pixels->x, dst->pixels->y, dst->pixels->width, dst->pixels->height); - pixman_region_intersect (&clip, &clip, clipPict->hasCompositeClip ? - &clipPict->compositeClip : NULL); + status = pixman_region_intersect (&clip, &clip, + clipPict->hasCompositeClip ? + &clipPict->compositeClip : + NULL); + if (status != PIXMAN_REGION_STATUS_SUCCESS) + { + pixman_region_fini (&clip); + return 1; + } if (clipPict->alphaMap) { pixman_region_translate (&clip, -clipPict->alphaOrigin.x, -clipPict->alphaOrigin.y); - pixman_region_intersect (&clip, &clip, - clipPict->alphaMap->hasCompositeClip ? - &clipPict->alphaMap->compositeClip : NULL); + status = pixman_region_intersect (&clip, &clip, + clipPict->alphaMap->hasCompositeClip ? + &clipPict->alphaMap->compositeClip : + NULL); + if (status != PIXMAN_REGION_STATUS_SUCCESS) + { + pixman_region_fini (&clip); + return 1; + } pixman_region_translate (&clip, clipPict->alphaOrigin.x, clipPict->alphaOrigin.y); @@ -236,13 +250,25 @@ pixman_color_rects (pixman_image_t *dst, for (i = 0; i < nRect; i++) { - pixman_region_union_rect (&rects_as_region, &rects_as_region, - rects[i].x, rects[i].y, - rects[i].width, rects[i].height); + status = pixman_region_union_rect (&rects_as_region, &rects_as_region, + rects[i].x, rects[i].y, + rects[i].width, rects[i].height); + if (status != PIXMAN_REGION_STATUS_SUCCESS) + { + break; + } } - pixman_region_intersect (&rects_as_region, &rects_as_region, &clip); + /* any earlier failure will also trigger a failure here... */ + status = pixman_region_intersect (&rects_as_region, + &rects_as_region, + &clip); pixman_region_fini (&clip); + if (status != PIXMAN_REGION_STATUS_SUCCESS) + { + pixman_region_fini (&rects_as_region); + return 1; + } n_clipped_rects = pixman_region_num_rects (&rects_as_region); clipped_rects = pixman_region_rects (&rects_as_region); @@ -275,9 +301,11 @@ pixman_color_rects (pixman_image_t *dst, rects[i].y += yoff; } } + + return 0; } -void pixman_fill_rectangle (pixman_operator_t op, +int pixman_fill_rectangle (pixman_operator_t op, pixman_image_t *dst, const pixman_color_t *color, int x, @@ -292,16 +320,17 @@ void pixman_fill_rectangle (pixman_operator_t op, rect.width = width; rect.height = height; - pixman_fill_rectangles (op, dst, color, &rect, 1); + return pixman_fill_rectangles (op, dst, color, &rect, 1); } -void +int pixman_fill_rectangles (pixman_operator_t op, pixman_image_t *dst, const pixman_color_t *color, const pixman_rectangle_t *rects, int nRects) { + int ret = 1; pixman_color_t color_s = *color; if (color_s.alpha == 0xffff) @@ -316,12 +345,16 @@ pixman_fill_rectangles (pixman_operator_t op, { /* We cast away the constness of rects here, because pixman_color_rects temporarily modifies it */ - pixman_color_rects (dst, dst, &color_s, nRects, (pixman_rectangle_t *)rects, 0, 0); - if (dst->alphaMap) - pixman_color_rects (dst->alphaMap, dst, - &color_s, nRects, (pixman_rectangle_t *)rects, - dst->alphaOrigin.x, - dst->alphaOrigin.y); + ret = pixman_color_rects (dst, dst, + &color_s, + nRects, (pixman_rectangle_t *)rects, + 0, 0); + if (!ret && dst->alphaMap) + ret = pixman_color_rects (dst->alphaMap, dst, + &color_s, + nRects, (pixman_rectangle_t *)rects, + dst->alphaOrigin.x, + dst->alphaOrigin.y); } else { @@ -364,9 +397,12 @@ pixman_fill_rectangles (pixman_operator_t op, } pixman_image_destroy (src); + ret = 0; bail2: FbPixelsDestroy (pixels); bail1: ; } + + return ret; } diff --git a/pixman/src/ictrap.c b/pixman/src/ictrap.c index 252fa69a5..3e6b8c6d2 100644 --- a/pixman/src/ictrap.c +++ b/pixman/src/ictrap.c @@ -102,10 +102,7 @@ pixman_trapezoid_bounds (int ntrap, const pixman_trapezoid_t *traps, pixman_box1 } } -/* XXX: There are failure cases in this function. Don't we need to - * propagate the errors out? - */ -void +int pixman_composite_trapezoids (pixman_operator_t op, pixman_image_t *src, pixman_image_t *dst, @@ -114,15 +111,16 @@ pixman_composite_trapezoids (pixman_operator_t op, const pixman_trapezoid_t *traps, int ntraps) { - pixman_image_t *image = NULL; - pixman_box16_t traps_bounds, dst_bounds, bounds; - pixman_region16_t traps_region, dst_region; - int16_t xDst, yDst; - int16_t xRel, yRel; - pixman_format_t *format; + pixman_image_t *image = NULL; + pixman_box16_t traps_bounds, dst_bounds, bounds; + pixman_region16_t traps_region, dst_region; + int16_t xDst, yDst; + int16_t xRel, yRel; + pixman_format_t *format; + pixman_region_status_t status; if (ntraps == 0) - return; + return 0; /* * Check for solid alpha add @@ -131,7 +129,7 @@ pixman_composite_trapezoids (pixman_operator_t op, { for (; ntraps; ntraps--, traps++) fbRasterizeTrapezoid (dst, traps, 0, 0); - return; + return 0; } xDst = traps[0].left.p1.x >> 16; @@ -149,7 +147,12 @@ pixman_composite_trapezoids (pixman_operator_t op, dst_bounds.y2 = pixman_image_get_height (dst); pixman_region_init_with_extents (&dst_region, &dst_bounds); - pixman_region_intersect (&traps_region, &traps_region, &dst_region); + status = pixman_region_intersect (&traps_region, &traps_region, &dst_region); + if (status != PIXMAN_REGION_STATUS_SUCCESS) { + pixman_region_fini (&traps_region); + pixman_region_fini (&dst_region); + return 1; + } bounds = *(pixman_region_extents (&traps_region)); @@ -157,11 +160,11 @@ pixman_composite_trapezoids (pixman_operator_t op, pixman_region_fini (&dst_region); if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2) - return; + return 0; format = pixman_format_create (PIXMAN_FORMAT_NAME_A8); if (!format) - return; + return 1; image = FbCreateAlphaPicture (dst, format, bounds.x2 - bounds.x1, @@ -169,7 +172,7 @@ pixman_composite_trapezoids (pixman_operator_t op, if (!image) { pixman_format_destroy (format); - return; + return 1; } for (; ntraps; ntraps--, traps++) @@ -189,6 +192,8 @@ pixman_composite_trapezoids (pixman_operator_t op, pixman_image_destroy (image); pixman_format_destroy (format); + + return 0; } void diff --git a/pixman/src/pixman-remap.h b/pixman/src/pixman-remap.h index 02ab3c4c6..6004fe7f6 100644 --- a/pixman/src/pixman-remap.h +++ b/pixman/src/pixman-remap.h @@ -78,4 +78,3 @@ #define RenderLineFixedEdgeInit _cairo_pixman_render_line_fixed_edge_init #define RenderSampleCeilY _cairo_pixman_render_sample_ceil_y #define RenderSampleFloorY _cairo_pixman_render_sample_floor_y -#define fbSolidFillmmx _cairo_pixman_solid_fill_mmx diff --git a/pixman/src/pixman.h b/pixman/src/pixman.h index 5c1212796..fb2ccf79a 100644 --- a/pixman/src/pixman.h +++ b/pixman/src/pixman.h @@ -100,7 +100,7 @@ SOFTWARE. #include "pixman-remap.h" #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun__) -#define pixman_private __attribute__((__visibility__("hidden"))) +#define pixman_private __attribute__((__visibility__("hidden"),__warn_unused_result__)) #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) #define pixman_private __hidden #else /* not gcc >= 3.3 and not Sun Studio >= 8 */ @@ -448,7 +448,7 @@ pixman_pixel_to_color (const pixman_format_t *format, /* icrect.c */ -pixman_private void +pixman_private int pixman_fill_rectangle (pixman_operator_t op, pixman_image_t *dst, const pixman_color_t *color, @@ -457,7 +457,7 @@ pixman_fill_rectangle (pixman_operator_t op, unsigned int width, unsigned int height); -pixman_private void +pixman_private int pixman_fill_rectangles (pixman_operator_t op, pixman_image_t *dst, const pixman_color_t *color, @@ -466,7 +466,7 @@ pixman_fill_rectangles (pixman_operator_t op, /* ictrap.c */ -pixman_private void +pixman_private int pixman_composite_trapezoids (pixman_operator_t op, pixman_image_t *src, pixman_image_t *dst, diff --git a/src/cairo-arc.c b/src/cairo-arc.c index 377da84fe..89e6ce1a6 100644 --- a/src/cairo-arc.c +++ b/src/cairo-arc.c @@ -87,7 +87,7 @@ _arc_max_angle_for_tolerance_normalized (double tolerance) { M_PI / 10.0, 1.73863223499021216974e-08 }, { M_PI / 11.0, 9.81410988043554039085e-09 }, }; - int table_size = ARRAY_LEN (table); + int table_size = ARRAY_LENGTH (table); for (i = 0; i < table_size; i++) if (table[i].error < tolerance) diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c index b5b783c83..92d38f248 100644 --- a/src/cairo-atsui-font.c +++ b/src/cairo-atsui-font.c @@ -116,7 +116,7 @@ _cairo_atsui_font_face_scaled_font_create (void *abstract_face, ATSUStyle style; err = ATSUCreateStyle (&style); - err = ATSUSetAttributes(style, ARRAY_LEN (styleTags), + err = ATSUSetAttributes(style, ARRAY_LENGTH (styleTags), styleTags, styleSizes, styleValues); return _cairo_atsui_font_create_scaled (&font_face->base, font_face->font_id, style, @@ -230,8 +230,13 @@ _cairo_atsui_font_create_scaled (cairo_font_face_t *font_face, if (font == NULL) return CAIRO_STATUS_NO_MEMORY; - _cairo_scaled_font_init(&font->base, font_face, font_matrix, ctm, options, - &cairo_atsui_scaled_font_backend); + status = _cairo_scaled_font_init (&font->base, + font_face, font_matrix, ctm, options, + &cairo_atsui_scaled_font_backend); + if (status) { + free (font); + return status; + } _cairo_matrix_compute_scale_factors (&font->base.scale, &xscale, &yscale, 1); @@ -372,7 +377,7 @@ _cairo_atsui_font_create_toy(cairo_toy_font_face_t *toy_face, ByteCount styleSizes[] = { sizeof(Boolean), sizeof(Boolean), sizeof(ATSUFontID) }; - err = ATSUSetAttributes(style, ARRAY_LEN (styleTags), + err = ATSUSetAttributes(style, ARRAY_LENGTH (styleTags), styleTags, styleSizes, styleValues); } @@ -680,8 +685,9 @@ _cairo_atsui_scaled_font_init_glyph_surface (cairo_atsui_font_t *scaled_font, if (theGlyph == kATSDeletedGlyphcode) { surface = (cairo_image_surface_t *)cairo_image_surface_create (CAIRO_FORMAT_A8, 2, 2); - if (!surface) - return CAIRO_STATUS_NO_MEMORY; + if (cairo_surface_status (surface)) + return cairo_surface_status (surface); + _cairo_scaled_glyph_set_surface (scaled_glyph, &base, surface); @@ -746,8 +752,8 @@ _cairo_atsui_scaled_font_init_glyph_surface (cairo_atsui_font_t *scaled_font, /* create the glyph mask surface */ surface = (cairo_image_surface_t *)cairo_image_surface_create (format, bbox.size.width, bbox.size.height); - if (!surface) - return CAIRO_STATUS_NO_MEMORY; + if (cairo_surface_status (surface)) + return cairo_surface_status (surface); /* Create a CGBitmapContext for the dest surface for drawing into */ { diff --git a/src/cairo-bentley-ottmann.c b/src/cairo-bentley-ottmann.c index 873bfd62d..bbae87502 100644 --- a/src/cairo-bentley-ottmann.c +++ b/src/cairo-bentley-ottmann.c @@ -137,6 +137,7 @@ typedef struct _cairo_bo_sweep_line { int32_t current_y; } cairo_bo_sweep_line_t; + static inline int _cairo_bo_point32_compare (cairo_bo_point32_t const *a, cairo_bo_point32_t const *b) @@ -692,13 +693,16 @@ _cairo_bo_event_init (cairo_bo_event_t *event, event->point = point; } -static void +static cairo_status_t _cairo_bo_event_queue_insert (cairo_bo_event_queue_t *queue, cairo_bo_event_t *event) { + cairo_status_t status = CAIRO_STATUS_SUCCESS; /* 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) + status = CAIRO_STATUS_NO_MEMORY; + return status; } static void @@ -796,7 +800,7 @@ _cairo_bo_event_queue_fini (cairo_bo_event_queue_t *event_queue) free (event_queue->sorted_startstop_event_ptrs); } -static void +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 +810,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 +818,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 +832,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 +852,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 +862,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 +882,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 @@ -1057,7 +1065,6 @@ _cairo_bo_edge_end_trap (cairo_bo_edge_t *left, cairo_bo_traps_t *bo_traps) { cairo_fixed_t fixed_top, fixed_bot; - cairo_status_t status = CAIRO_STATUS_SUCCESS; cairo_bo_trap_t *trap = left->deferred_trap; cairo_bo_edge_t *right; @@ -1099,11 +1106,11 @@ _cairo_bo_edge_end_trap (cairo_bo_edge_t *left, left_bot.x != right_bot.x || left_bot.y != right_bot.y) { - status = _cairo_traps_add_trap_from_points (bo_traps->traps, - fixed_top, - fixed_bot, - left_top, left_bot, - right_top, right_bot); + _cairo_traps_add_trap_from_points (bo_traps->traps, + fixed_top, + fixed_bot, + left_top, left_bot, + right_top, right_bot); #if DEBUG_PRINT_STATE printf ("Deferred trap: left=(%08x, %08x)-(%08x,%08x) " @@ -1117,7 +1124,8 @@ _cairo_bo_edge_end_trap (cairo_bo_edge_t *left, _cairo_freelist_free (&bo_traps->freelist, trap); left->deferred_trap = NULL; - return status; + + return _cairo_traps_status (bo_traps->traps); } /* Start a new trapezoid at the given top y coordinate, whose edges @@ -1254,7 +1262,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; @@ -1264,7 +1272,10 @@ _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); @@ -1296,7 +1307,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 +1317,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 +1343,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 +1373,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); @@ -1771,7 +1794,7 @@ main (void) unsigned int i, num_random; test_t *test; - for (i = 0; i < ARRAY_LEN (tests); i++) { + for (i = 0; i < ARRAY_LENGTH (tests); i++) { test = &tests[i]; run_test (test->name, test->edges, test->num_edges); } diff --git a/src/cairo-cff-subset.c b/src/cairo-cff-subset.c index 1cdedee18..ab61ae265 100644 --- a/src/cairo-cff-subset.c +++ b/src/cairo-cff-subset.c @@ -895,7 +895,7 @@ cairo_cff_font_read_font (cairo_cff_font_t *font) cairo_int_status_t status; unsigned int i; - for (i = 0; i < ARRAY_LEN (font_read_funcs); i++) { + for (i = 0; i < ARRAY_LENGTH (font_read_funcs); i++) { status = font_read_funcs[i] (font); if (status) return status; @@ -955,7 +955,7 @@ cairo_cff_font_subset_dict_strings (cairo_cff_font_t *font, cairo_status_t status; unsigned int i; - for (i = 0; i < ARRAY_LEN (dict_strings); i++) { + for (i = 0; i < ARRAY_LENGTH (dict_strings); i++) { status = cairo_cff_font_subset_dict_string (font, dict, dict_strings[i]); if (status) return status; @@ -1316,7 +1316,7 @@ cairo_cff_font_write_subset (cairo_cff_font_t *font) cairo_int_status_t status; unsigned int i; - for (i = 0; i < ARRAY_LEN (font_write_funcs); i++) { + for (i = 0; i < ARRAY_LENGTH (font_write_funcs); i++) { status = font_write_funcs[i] (font); if (status) return status; diff --git a/src/cairo-clip-private.h b/src/cairo-clip-private.h index fbcb35216..e7190cf1d 100644 --- a/src/cairo-clip-private.h +++ b/src/cairo-clip-private.h @@ -84,15 +84,15 @@ struct _cairo_clip { cairo_private void _cairo_clip_init (cairo_clip_t *clip, cairo_surface_t *target); -cairo_private void +cairo_private cairo_status_t _cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other); -cairo_private void +cairo_private cairo_status_t _cairo_clip_init_deep_copy (cairo_clip_t *clip, cairo_clip_t *other, cairo_surface_t *target); -cairo_private cairo_status_t +cairo_private void _cairo_clip_reset (cairo_clip_t *clip); cairo_private cairo_status_t diff --git a/src/cairo-clip.c b/src/cairo-clip.c index ea4ada3fa..6e52ab28e 100644 --- a/src/cairo-clip.c +++ b/src/cairo-clip.c @@ -67,7 +67,7 @@ _cairo_clip_init (cairo_clip_t *clip, cairo_surface_t *target) clip->path = NULL; } -void +cairo_status_t _cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other) { clip->mode = other->mode; @@ -80,16 +80,23 @@ _cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other) pixman_region_init (&clip->region); if (other->has_region) { - pixman_region_copy (&clip->region, &other->region); + if (pixman_region_copy (&clip->region, &other->region) != + PIXMAN_REGION_STATUS_SUCCESS) { + pixman_region_fini (&clip->region); + cairo_surface_destroy (clip->surface); + return CAIRO_STATUS_NO_MEMORY; + } clip->has_region = TRUE; } else { clip->has_region = FALSE; } clip->path = _cairo_clip_path_reference (other->path); + + return CAIRO_STATUS_SUCCESS; } -cairo_status_t +void _cairo_clip_reset (cairo_clip_t *clip) { /* destroy any existing clip-region artifacts */ @@ -110,8 +117,6 @@ _cairo_clip_reset (cairo_clip_t *clip) _cairo_clip_path_destroy (clip->path); clip->path = NULL; - - return CAIRO_STATUS_SUCCESS; } static cairo_status_t @@ -195,6 +200,8 @@ cairo_status_t _cairo_clip_intersect_to_region (cairo_clip_t *clip, pixman_region16_t *region) { + pixman_region_status_t pixman_status; + if (!clip) return CAIRO_STATUS_SUCCESS; @@ -202,8 +209,11 @@ _cairo_clip_intersect_to_region (cairo_clip_t *clip, /* Intersect clip path into region. */ } - if (clip->has_region) - pixman_region_intersect (region, &clip->region, region); + if (clip->has_region) { + pixman_status = pixman_region_intersect (region, &clip->region, region); + if (pixman_status != PIXMAN_REGION_STATUS_SUCCESS) + return CAIRO_STATUS_NO_MEMORY; + } if (clip->surface) { cairo_status_t status = CAIRO_STATUS_SUCCESS; @@ -337,18 +347,20 @@ _cairo_clip_intersect_region (cairo_clip_t *clip, status = CAIRO_STATUS_SUCCESS; if (!clip->has_region) { - pixman_region_copy (&clip->region, ®ion); - clip->has_region = TRUE; + if (pixman_region_copy (&clip->region, ®ion) == + PIXMAN_REGION_STATUS_SUCCESS) + clip->has_region = TRUE; } else { pixman_region16_t intersection; pixman_region_init (&intersection); - if (PIXMAN_REGION_STATUS_SUCCESS == - pixman_region_intersect (&intersection, &clip->region, ®ion)) { - pixman_region_copy (&clip->region, &intersection); - } else { - status = CAIRO_STATUS_NO_MEMORY; - } + if (PIXMAN_REGION_STATUS_SUCCESS != + pixman_region_intersect (&intersection, + &clip->region, + ®ion) || + PIXMAN_REGION_STATUS_SUCCESS != + pixman_region_copy (&clip->region, &intersection)) + status = CAIRO_STATUS_NO_MEMORY; pixman_region_fini (&intersection); } @@ -539,7 +551,7 @@ _cairo_clip_path_reapply_clip_path (cairo_clip_t *clip, clip_path->antialias); } -void +cairo_status_t _cairo_clip_init_deep_copy (cairo_clip_t *clip, cairo_clip_t *other, cairo_surface_t *target) @@ -551,17 +563,21 @@ _cairo_clip_init_deep_copy (cairo_clip_t *clip, * whatever the right handling is happen */ } else { if (other->has_region) { - pixman_region_copy (&clip->region, &other->region); - clip->has_region = TRUE; + if (pixman_region_copy (&clip->region, &other->region) != + PIXMAN_REGION_STATUS_SUCCESS) + goto BAIL; + clip->has_region = TRUE; } if (other->surface) { - _cairo_surface_clone_similar (target, other->surface, + if (_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); + &clip->surface) != + CAIRO_STATUS_SUCCESS) + goto BAIL; clip->surface_rect = other->surface_rect; } @@ -569,6 +585,16 @@ _cairo_clip_init_deep_copy (cairo_clip_t *clip, _cairo_clip_path_reapply_clip_path (clip, other->path); } } + + return CAIRO_STATUS_SUCCESS; + +BAIL: + if (clip->has_region) + pixman_region_fini (&clip->region); + if (clip->surface) + cairo_surface_destroy (clip->surface); + + return CAIRO_STATUS_NO_MEMORY; } const cairo_rectangle_list_t _cairo_rectangles_nil = @@ -625,10 +651,11 @@ _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)) { + if (_cairo_surface_get_extents (_cairo_gstate_get_target (gstate), + &extents) != 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 0da7d6745..fa18ffd53 100644 --- a/src/cairo-ft-font.c +++ b/src/cairo-ft-font.c @@ -819,8 +819,11 @@ _get_bitmap_surface (FT_Bitmap *bitmap, stride = bitmap->pitch; stride_rgba = (width_rgba * 4 + 3) & ~3; data_rgba = calloc (1, stride_rgba * height); - if (data_rgba == NULL) + if (data_rgba == NULL) { + if (own_buffer) + free (bitmap->buffer); return CAIRO_STATUS_NO_MEMORY; + } os = 1; switch (font_options->subpixel_order) { @@ -885,6 +888,8 @@ _get_bitmap_surface (FT_Bitmap *bitmap, case FT_PIXEL_MODE_GRAY4: /* These could be triggered by very rare types of TrueType fonts */ default: + if (own_buffer) + free (bitmap->buffer); return CAIRO_STATUS_NO_MEMORY; } @@ -1158,24 +1163,33 @@ _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. */ @@ -1425,6 +1439,7 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t *unscaled, FT_Face face; FT_Size_Metrics *metrics; cairo_font_extents_t fs_metrics; + cairo_status_t status; face = _cairo_ft_unscaled_font_lock_face (unscaled); if (!face) @@ -1445,10 +1460,15 @@ _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) { + free (scaled_font); + _cairo_ft_unscaled_font_unlock_face (unscaled); + return NULL; + } _cairo_ft_unscaled_font_set_scale (unscaled, &scaled_font->base.scale); @@ -1624,8 +1644,10 @@ _move_to (FT_Vector *to, void *closure) x = _cairo_fixed_from_26_6 (to->x); y = _cairo_fixed_from_26_6 (to->y); - _cairo_path_fixed_close_path (path); - _cairo_path_fixed_move_to (path, x, y); + if (_cairo_path_fixed_close_path (path) != CAIRO_STATUS_SUCCESS) + return 1; + if (_cairo_path_fixed_move_to (path, x, y) != CAIRO_STATUS_SUCCESS) + return 1; return 0; } @@ -1639,7 +1661,8 @@ _line_to (FT_Vector *to, void *closure) x = _cairo_fixed_from_26_6 (to->x); y = _cairo_fixed_from_26_6 (to->y); - _cairo_path_fixed_line_to (path, x, y); + if (_cairo_path_fixed_line_to (path, x, y) != CAIRO_STATUS_SUCCESS) + return 1; return 0; } @@ -1655,7 +1678,9 @@ _conic_to (FT_Vector *control, FT_Vector *to, void *closure) cairo_fixed_t x3, y3; cairo_point_t conic; - _cairo_path_fixed_get_current_point (path, &x0, &y0); + if (_cairo_path_fixed_get_current_point (path, &x0, &y0) != + CAIRO_STATUS_SUCCESS) + return 1; conic.x = _cairo_fixed_from_26_6 (control->x); conic.y = _cairo_fixed_from_26_6 (control->y); @@ -1669,10 +1694,11 @@ _conic_to (FT_Vector *control, FT_Vector *to, void *closure) x2 = x3 + 2.0/3.0 * (conic.x - x3); y2 = y3 + 2.0/3.0 * (conic.y - y3); - _cairo_path_fixed_curve_to (path, - x1, y1, - x2, y2, - x3, y3); + if (_cairo_path_fixed_curve_to (path, + x1, y1, + x2, y2, + x3, y3) != CAIRO_STATUS_SUCCESS) + return 1; return 0; } @@ -1695,10 +1721,11 @@ _cubic_to (FT_Vector *control1, FT_Vector *control2, x2 = _cairo_fixed_from_26_6 (to->x); y2 = _cairo_fixed_from_26_6 (to->y); - _cairo_path_fixed_curve_to (path, - x0, y0, - x1, y1, - x2, y2); + if (_cairo_path_fixed_curve_to (path, + x0, y0, + x1, y1, + x2, y2) != CAIRO_STATUS_SUCCESS) + return 1; return 0; } @@ -1723,6 +1750,7 @@ _decompose_glyph_outline (FT_Face face, FT_GlyphSlot glyph; cairo_path_fixed_t *path; + cairo_status_t status, status2; path = _cairo_path_fixed_create (); if (!path) @@ -1730,15 +1758,20 @@ _decompose_glyph_outline (FT_Face face, glyph = face->glyph; + status = CAIRO_STATUS_SUCCESS; /* 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)) + status = CAIRO_STATUS_NO_MEMORY; - _cairo_path_fixed_close_path (path); + status2 = _cairo_path_fixed_close_path (path); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; - *pathp = path; + if (status == CAIRO_STATUS_SUCCESS) + *pathp = path; - return CAIRO_STATUS_SUCCESS; + return status; } /* diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c index 41da4f408..c5d5f38f8 100644 --- a/src/cairo-gstate.c +++ b/src/cairo-gstate.c @@ -129,7 +129,9 @@ _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); + status = _cairo_clip_init_copy (&gstate->clip, &other->clip); + if (status) + return status; gstate->target = cairo_surface_reference (other->target); /* parent_target is always set to NULL; it's only ever set by redirect_target */ @@ -299,9 +301,11 @@ _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); @@ -317,13 +321,17 @@ _cairo_gstate_redirect_target (cairo_gstate_t *gstate, cairo_surface_t *child) gstate->target = cairo_surface_reference (child); _cairo_clip_reset (&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; } /** @@ -403,7 +411,7 @@ _cairo_gstate_set_source (cairo_gstate_t *gstate, if (source->status) return source->status; - cairo_pattern_reference (source); + source = cairo_pattern_reference (source); cairo_pattern_destroy (gstate->source); gstate->source = source; gstate->source_ctm_inverse = gstate->ctm_inverse; @@ -648,13 +656,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; @@ -678,49 +689,39 @@ _cairo_gstate_set_matrix (cairo_gstate_t *gstate, return CAIRO_STATUS_SUCCESS; } -cairo_status_t +void _cairo_gstate_identity_matrix (cairo_gstate_t *gstate) { _cairo_gstate_unset_scaled_font (gstate); cairo_matrix_init_identity (&gstate->ctm); cairo_matrix_init_identity (&gstate->ctm_inverse); - - return CAIRO_STATUS_SUCCESS; } -cairo_status_t +void _cairo_gstate_user_to_device (cairo_gstate_t *gstate, double *x, double *y) { cairo_matrix_transform_point (&gstate->ctm, x, y); - - return CAIRO_STATUS_SUCCESS; } -cairo_status_t +void _cairo_gstate_user_to_device_distance (cairo_gstate_t *gstate, double *dx, double *dy) { cairo_matrix_transform_distance (&gstate->ctm, dx, dy); - - return CAIRO_STATUS_SUCCESS; } -cairo_status_t +void _cairo_gstate_device_to_user (cairo_gstate_t *gstate, double *x, double *y) { cairo_matrix_transform_point (&gstate->ctm_inverse, x, y); - - return CAIRO_STATUS_SUCCESS; } -cairo_status_t +void _cairo_gstate_device_to_user_distance (cairo_gstate_t *gstate, double *dx, double *dy) { cairo_matrix_transform_distance (&gstate->ctm_inverse, dx, dy); - - return CAIRO_STATUS_SUCCESS; } void @@ -1066,29 +1067,13 @@ BAIL: cairo_status_t _cairo_gstate_copy_page (cairo_gstate_t *gstate) { - cairo_int_status_t status; - - status = _cairo_surface_copy_page (gstate->target); - - /* It's fine if some surfaces just don't support this. */ - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - return CAIRO_STATUS_SUCCESS; - - return status; + return _cairo_surface_copy_page (gstate->target); } cairo_status_t _cairo_gstate_show_page (cairo_gstate_t *gstate) { - cairo_int_status_t status; - - status = _cairo_surface_show_page (gstate->target); - - /* It's fine if some surfaces just don't support this. */ - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - return CAIRO_STATUS_SUCCESS; - - return status; + return _cairo_surface_show_page (gstate->target); } static void @@ -1190,7 +1175,9 @@ _cairo_gstate_fill_extents (cairo_gstate_t *gstate, cairo_status_t _cairo_gstate_reset_clip (cairo_gstate_t *gstate) { - return _cairo_clip_reset (&gstate->clip); + _cairo_clip_reset (&gstate->clip); + + return CAIRO_STATUS_SUCCESS; } cairo_status_t @@ -1255,12 +1242,15 @@ _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); + if (status) + return status; cairo_font_face_destroy (font_face); return CAIRO_STATUS_SUCCESS; @@ -1457,10 +1447,12 @@ _cairo_gstate_ensure_scaled_font (cairo_gstate_t *gstate) &gstate->font_matrix, &gstate->ctm, &options); - - if (!gstate->scaled_font) + if (gstate->scaled_font == NULL) return CAIRO_STATUS_NO_MEMORY; + if (cairo_scaled_font_status (gstate->scaled_font)) + return cairo_scaled_font_status (gstate->scaled_font); + return CAIRO_STATUS_SUCCESS; } diff --git a/src/cairo-hash.c b/src/cairo-hash.c index 31de81106..99343754f 100644 --- a/src/cairo-hash.c +++ b/src/cairo-hash.c @@ -115,7 +115,7 @@ static const cairo_hash_table_arrangement_t hash_table_arrangements [] = { { 268435456, 590559793, 590559791 } }; -#define NUM_HASH_TABLE_ARRANGEMENTS ARRAY_LEN (hash_table_arrangements) +#define NUM_HASH_TABLE_ARRANGEMENTS ARRAY_LENGTH (hash_table_arrangements) struct _cairo_hash_table { cairo_hash_keys_equal_func_t keys_equal; @@ -481,8 +481,12 @@ _cairo_hash_table_insert (cairo_hash_table_t *hash_table, hash_table->live_entries++; status = _cairo_hash_table_resize (hash_table); - if (status) + if (status) { + /* abort the insert... */ + *entry = DEAD_ENTRY; + hash_table->live_entries--; return status; + } return CAIRO_STATUS_SUCCESS; } @@ -561,6 +565,9 @@ _cairo_hash_table_foreach (cairo_hash_table_t *hash_table, * the table may need resizing. Just do this every time * as the check is inexpensive. */ - if (--hash_table->iterating == 0) + if (--hash_table->iterating == 0) { + /* Should we fail to shrink the hash table, it is left unaltered, + * and we don't need to propagate the error status. */ _cairo_hash_table_resize (hash_table); + } } diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index 627901216..a3da89407 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -241,6 +241,9 @@ _cairo_image_surface_create_with_masks (unsigned char *data, surface = _cairo_image_surface_create_for_pixman_image (pixman_image, cairo_format); + if (cairo_surface_status (surface)) { + pixman_image_destroy (pixman_image); + } return surface; } @@ -315,6 +318,9 @@ cairo_image_surface_create (cairo_format_t format, } surface = _cairo_image_surface_create_for_pixman_image (pixman_image, format); + if (cairo_surface_status (surface)) { + pixman_image_destroy (pixman_image); + } return surface; } @@ -395,6 +401,9 @@ cairo_image_surface_create_for_data (unsigned char *data, } surface = _cairo_image_surface_create_for_pixman_image (pixman_image, format); + if (cairo_surface_status (surface)) { + pixman_image_destroy (pixman_image); + } return surface; } @@ -690,7 +699,8 @@ _cairo_image_surface_set_matrix (cairo_image_surface_t *surface, _cairo_matrix_to_pixman_matrix (matrix, &pixman_transform); - pixman_image_set_transform (surface->pixman_image, &pixman_transform); + if (pixman_image_set_transform (surface->pixman_image, &pixman_transform)) + return CAIRO_STATUS_NO_MEMORY; return CAIRO_STATUS_SUCCESS; } @@ -907,8 +917,10 @@ _cairo_image_surface_fill_rectangles (void *abstract_surface, pixman_color.alpha = color->alpha_short; /* XXX: The pixman_rectangle_t cast is evil... it needs to go away somehow. */ - pixman_fill_rectangles (_pixman_operator(op), surface->pixman_image, - &pixman_color, (pixman_rectangle_t *) rects, num_rects); + if (pixman_fill_rectangles (_pixman_operator(op), surface->pixman_image, + &pixman_color, + (pixman_rectangle_t *) rects, num_rects)) + return CAIRO_STATUS_NO_MEMORY; return CAIRO_STATUS_SUCCESS; } @@ -1047,7 +1059,8 @@ _cairo_image_surface_set_clip_region (void *abstract_surface, { cairo_image_surface_t *surface = (cairo_image_surface_t *) abstract_surface; - pixman_image_set_clip_region (surface->pixman_image, region); + if (pixman_image_set_clip_region (surface->pixman_image, region)) + return CAIRO_STATUS_NO_MEMORY; surface->has_clip = region != NULL; diff --git a/src/cairo-matrix.c b/src/cairo-matrix.c index 75c27b234..40828f026 100644 --- a/src/cairo-matrix.c +++ b/src/cairo-matrix.c @@ -495,7 +495,7 @@ _cairo_matrix_compute_determinant (const cairo_matrix_t *matrix, } /* Compute the amount that each basis vector is scaled by. */ -cairo_status_t +void _cairo_matrix_compute_scale_factors (const cairo_matrix_t *matrix, double *sx, double *sy, int x_major) { @@ -535,8 +535,6 @@ _cairo_matrix_compute_scale_factors (const cairo_matrix_t *matrix, *sy = major; } } - - return CAIRO_STATUS_SUCCESS; } cairo_bool_t diff --git a/src/cairo-meta-surface.c b/src/cairo-meta-surface.c index 457bfe21a..56c702c80 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; } @@ -754,7 +756,7 @@ _cairo_meta_surface_replay (cairo_surface_t *surface, /* XXX Meta surface clipping is broken and requires some * cairo-gstate.c rewriting. Work around it for now. */ if (dev_path == NULL) - status = _cairo_clip_reset (&clip); + _cairo_clip_reset (&clip); else status = _cairo_clip_clip (&clip, dev_path, command->intersect_clip_path.fill_rule, diff --git a/src/cairo-output-stream-private.h b/src/cairo-output-stream-private.h index 0d5d29c46..26c18cb58 100644 --- a/src/cairo-output-stream-private.h +++ b/src/cairo-output-stream-private.h @@ -107,7 +107,7 @@ _cairo_output_stream_write_hex_string (cairo_output_stream_t *stream, const char *data, size_t length); -cairo_private int +cairo_private void _cairo_dtostr (char *buffer, size_t size, double d); cairo_private void diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c index cdf7d1da8..4401c5bd7 100644 --- a/src/cairo-output-stream.c +++ b/src/cairo-output-stream.c @@ -215,52 +215,49 @@ _cairo_output_stream_write_hex_string (cairo_output_stream_t *stream, * has been relicensed under the LGPL/MPL dual license for inclusion * into cairo (see COPYING). -- Kristian Høgsberg <krh@redhat.com> */ - -int +void _cairo_dtostr (char *buffer, size_t size, double d) { - struct lconv *locale_data; - const char *decimal_point; - int decimal_point_len; - char *p; - int decimal_len; - - /* Omit the minus sign from negative zero. */ - if (d == 0.0) - d = 0.0; + struct lconv *locale_data; + const char *decimal_point; + int decimal_point_len; + char *p; + int decimal_len; - snprintf (buffer, size, "%f", d); + /* Omit the minus sign from negative zero. */ + if (d == 0.0) + d = 0.0; - locale_data = localeconv (); - decimal_point = locale_data->decimal_point; - decimal_point_len = strlen (decimal_point); + snprintf (buffer, size, "%f", d); - assert (decimal_point_len != 0); - p = buffer; + locale_data = localeconv (); + decimal_point = locale_data->decimal_point; + decimal_point_len = strlen (decimal_point); - if (*p == '+' || *p == '-') - p++; + assert (decimal_point_len != 0); + p = buffer; - while (isdigit (*p)) - p++; + if (*p == '+' || *p == '-') + p++; - if (strncmp (p, decimal_point, decimal_point_len) == 0) { - *p = '.'; - decimal_len = strlen (p + decimal_point_len); - memmove (p + 1, p + decimal_point_len, decimal_len); - p[1 + decimal_len] = 0; + while (isdigit (*p)) + p++; - /* Remove trailing zeros and decimal point if possible. */ - for (p = p + decimal_len; *p == '0'; p--) - *p = 0; + if (strncmp (p, decimal_point, decimal_point_len) == 0) { + *p = '.'; + decimal_len = strlen (p + decimal_point_len); + memmove (p + 1, p + decimal_point_len, decimal_len); + p[1 + decimal_len] = 0; - if (*p == '.') { - *p = 0; - p--; - } - } + /* Remove trailing zeros and decimal point if possible. */ + for (p = p + decimal_len; *p == '0'; p--) + *p = 0; - return p + 1 - buffer; + if (*p == '.') { + *p = 0; + p--; + } + } } enum { @@ -279,7 +276,9 @@ void _cairo_output_stream_vprintf (cairo_output_stream_t *stream, const char *fmt, va_list ap) { - char buffer[512], single_fmt[32]; +#define SINGLE_FMT_BUFFER_SIZE 32 + char buffer[512], single_fmt[SINGLE_FMT_BUFFER_SIZE]; + int single_fmt_length; char *p; const char *f, *start; int length_modifier; @@ -315,9 +314,15 @@ _cairo_output_stream_vprintf (cairo_output_stream_t *stream, f++; } + /* The only format strings exist in the cairo implementation + * itself. So there's an internal consistency problem if any + * of them is larger than our format buffer size. */ + single_fmt_length = f - start + 1; + assert (single_fmt_length + 1 <= SINGLE_FMT_BUFFER_SIZE); + /* Reuse the format string for this conversion. */ - memcpy (single_fmt, start, f + 1 - start); - single_fmt[f + 1 - start] = '\0'; + memcpy (single_fmt, start, single_fmt_length); + single_fmt[single_fmt_length] = '\0'; /* Flush contents of buffer before snprintf()'ing into it. */ _cairo_output_stream_write (stream, buffer, p - buffer); diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c index c8e46124f..f788dc2fd 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; @@ -237,11 +244,12 @@ _paint_page (cairo_paginated_surface_t *surface) surface->width, surface->height); surface->backend->set_paginated_mode (surface->target, CAIRO_PAGINATED_MODE_ANALYZE); - _cairo_meta_surface_replay (surface->meta, analysis); + status = _cairo_meta_surface_replay (surface->meta, analysis); surface->backend->set_paginated_mode (surface->target, CAIRO_PAGINATED_MODE_RENDER); - if (analysis->status) { - status = analysis->status; + if (status || analysis->status) { + if (status == CAIRO_STATUS_SUCCESS) + status = analysis->status; cairo_surface_destroy (analysis); return status; } @@ -257,26 +265,29 @@ _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); + if (status) + goto CLEANUP_IMAGE; pattern = cairo_pattern_create_for_surface (image); cairo_matrix_init_scale (&matrix, x_scale, y_scale); cairo_pattern_set_matrix (pattern, &matrix); - _cairo_surface_paint (surface->target, CAIRO_OPERATOR_SOURCE, pattern); + status = _cairo_surface_paint (surface->target, CAIRO_OPERATOR_SOURCE, pattern); cairo_pattern_destroy (pattern); + CLEANUP_IMAGE: cairo_surface_destroy (image); } 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 +336,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); @@ -485,6 +498,7 @@ _cairo_paginated_surface_show_glyphs (void *abstract_surface, static cairo_surface_t * _cairo_paginated_surface_snapshot (void *abstract_other) { + cairo_status_t status; cairo_paginated_surface_t *other = abstract_other; /* XXX: Just making a snapshot of other->meta is what we really @@ -505,13 +519,19 @@ _cairo_paginated_surface_snapshot (void *abstract_other) cairo_rectangle_int16_t extents; 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); + surface = (cairo_surface_t*) &_cairo_surface_nil; + } return surface; #endif diff --git a/src/cairo-path-bounds.c b/src/cairo-path-bounds.c index 48b4393a7..5b60cf1c3 100644 --- a/src/cairo-path-bounds.c +++ b/src/cairo-path-bounds.c @@ -51,7 +51,7 @@ _cairo_path_bounder_init (cairo_path_bounder_t *bounder); static void _cairo_path_bounder_fini (cairo_path_bounder_t *bounder); -static cairo_status_t +static void _cairo_path_bounder_add_point (cairo_path_bounder_t *bounder, cairo_point_t *point); static cairo_status_t @@ -81,7 +81,7 @@ _cairo_path_bounder_fini (cairo_path_bounder_t *bounder) bounder->has_point = 0; } -static cairo_status_t +static void _cairo_path_bounder_add_point (cairo_path_bounder_t *bounder, cairo_point_t *point) { if (bounder->has_point) { @@ -104,8 +104,6 @@ _cairo_path_bounder_add_point (cairo_path_bounder_t *bounder, cairo_point_t *poi bounder->has_point = 1; } - - return CAIRO_STATUS_SUCCESS; } static cairo_status_t diff --git a/src/cairo-path-fill.c b/src/cairo-path-fill.c index b1b7a120d..25420297f 100644 --- a/src/cairo-path-fill.c +++ b/src/cairo-path-fill.c @@ -88,37 +88,28 @@ _cairo_filler_fini (cairo_filler_t *filler) static cairo_status_t _cairo_filler_move_to (void *closure, cairo_point_t *point) { - cairo_status_t status; cairo_filler_t *filler = closure; cairo_polygon_t *polygon = &filler->polygon; - status = _cairo_polygon_close (polygon); - if (status) - return status; - - status = _cairo_polygon_move_to (polygon, point); - if (status) - return status; + _cairo_polygon_close (polygon); + _cairo_polygon_move_to (polygon, point); filler->current_point = *point; - return CAIRO_STATUS_SUCCESS; + return _cairo_polygon_status (&filler->polygon); } static cairo_status_t _cairo_filler_line_to (void *closure, cairo_point_t *point) { - cairo_status_t status; cairo_filler_t *filler = closure; cairo_polygon_t *polygon = &filler->polygon; - status = _cairo_polygon_line_to (polygon, point); - if (status) - return status; + _cairo_polygon_line_to (polygon, point); filler->current_point = *point; - return CAIRO_STATUS_SUCCESS; + return _cairo_polygon_status (&filler->polygon); } static cairo_status_t @@ -138,15 +129,12 @@ _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; - for (i = 1; i < spline.num_points; i++) { - status = _cairo_polygon_line_to (polygon, &spline.points[i]); - if (status) - break; - } + for (i = 1; i < spline.num_points; i++) + _cairo_polygon_line_to (polygon, &spline.points[i]); CLEANUP_SPLINE: _cairo_spline_fini (&spline); @@ -159,15 +147,12 @@ _cairo_filler_curve_to (void *closure, static cairo_status_t _cairo_filler_close_path (void *closure) { - cairo_status_t status; cairo_filler_t *filler = closure; cairo_polygon_t *polygon = &filler->polygon; - status = _cairo_polygon_close (polygon); - if (status) - return status; + _cairo_polygon_close (polygon); - return CAIRO_STATUS_SUCCESS; + return _cairo_polygon_status (polygon); } static cairo_int_status_t @@ -201,7 +186,8 @@ _cairo_path_fixed_fill_to_traps (cairo_path_fixed_t *path, if (status) goto BAIL; - status = _cairo_polygon_close (&filler.polygon); + _cairo_polygon_close (&filler.polygon); + status = _cairo_polygon_status (&filler.polygon); if (status) goto BAIL; diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c index 09bafbf8e..d9f7ed2ca 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 +static cairo_status_t _cairo_stroker_init (cairo_stroker_t *stroker, cairo_stroke_style_t *stroke_style, cairo_matrix_t *ctm, @@ -148,7 +148,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 +156,18 @@ _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,6 +177,8 @@ _cairo_stroker_init (cairo_stroker_t *stroker, _cairo_stroker_start_dash (stroker); else stroker->dashed = FALSE; + + return CAIRO_STATUS_SUCCESS; } static void @@ -205,6 +210,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 +237,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 +259,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 +394,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; @@ -419,8 +441,14 @@ _cairo_stroker_add_cap (cairo_stroker_t *stroker, cairo_stroke_face_t *f) _cairo_polygon_line_to (&polygon, &occw); _cairo_polygon_line_to (&polygon, &f->ccw); _cairo_polygon_close (&polygon); + status = _cairo_polygon_status (&polygon); + + if (status == CAIRO_STATUS_SUCCESS) { + status = _cairo_bentley_ottmann_tessellate_polygon (stroker->traps, + &polygon, + CAIRO_FILL_RULE_WINDING); + } - status = _cairo_bentley_ottmann_tessellate_polygon (stroker->traps, &polygon, CAIRO_FILL_RULE_WINDING); _cairo_polygon_fini (&polygon); return status; @@ -967,9 +995,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, diff --git a/src/cairo-path.c b/src/cairo-path.c index ff4419132..cf2dd4d92 100644 --- a/src/cairo-path.c +++ b/src/cairo-path.c @@ -136,6 +136,7 @@ _cairo_path_count (cairo_path_t *path, double tolerance, cairo_bool_t flatten) { + cairo_status_t status; cpc_t cpc; cpc.count = 0; @@ -143,15 +144,17 @@ _cairo_path_count (cairo_path_t *path, 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; } @@ -307,12 +310,13 @@ _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) { + cairo_status_t status; cpp_t cpp; cpp.data = path->data; @@ -320,18 +324,22 @@ _cairo_path_populate (cairo_path_t *path, 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); + if (status) + return status; /* Sanity check the count */ assert (cpp.data - path->data == path->num_data); + + return status; } cairo_path_t * @@ -371,10 +379,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; } @@ -463,6 +469,7 @@ _cairo_path_append_to_context (const cairo_path_t *path, { int i; cairo_path_data_t *p; + cairo_status_t status; for (i=0; i < path->num_data; i += path->data[i].header.length) { p = &path->data[i]; @@ -495,6 +502,10 @@ _cairo_path_append_to_context (const cairo_path_t *path, default: return CAIRO_STATUS_INVALID_PATH_DATA; } + + status = cairo_status (cr); + if (status) + return status; } return CAIRO_STATUS_SUCCESS; diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index 80acdadee..ec8f0d05b 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -277,8 +277,8 @@ static struct { int size; } solid_pattern_cache; -static cairo_pattern_t * -_cairo_pattern_create_solid_from_cache (const cairo_color_t *color) +cairo_pattern_t * +_cairo_pattern_create_solid (const cairo_color_t *color) { cairo_solid_pattern_t *pattern = NULL; @@ -286,7 +286,7 @@ _cairo_pattern_create_solid_from_cache (const cairo_color_t *color) if (solid_pattern_cache.size) { int i = --solid_pattern_cache.size % - ARRAY_LEN (solid_pattern_cache.patterns); + ARRAY_LENGTH (solid_pattern_cache.patterns); pattern = solid_pattern_cache.patterns[i]; solid_pattern_cache.patterns[i] = NULL; } @@ -297,22 +297,13 @@ _cairo_pattern_create_solid_from_cache (const cairo_color_t *color) /* None cached, need to create a new pattern. */ pattern = malloc (sizeof (cairo_solid_pattern_t)); } - if (pattern != NULL) - _cairo_pattern_init_solid (pattern, color); - - return &pattern->base; -} - -cairo_pattern_t * -_cairo_pattern_create_solid (const cairo_color_t *color) -{ - cairo_pattern_t *pattern; - pattern = _cairo_pattern_create_solid_from_cache (color); if (pattern == NULL) - return (cairo_pattern_t *) &_cairo_pattern_nil.base; + pattern = (cairo_solid_pattern_t *) &_cairo_pattern_nil; + else + _cairo_pattern_init_solid (pattern, color); - return pattern; + return &pattern->base; } void @@ -322,7 +313,7 @@ _cairo_pattern_reset_static_data (void) CAIRO_MUTEX_LOCK (_cairo_pattern_solid_cache_lock); - for (i = 0; i < MIN (ARRAY_LEN (solid_pattern_cache.patterns), solid_pattern_cache.size); i++) { + for (i = 0; i < MIN (ARRAY_LENGTH (solid_pattern_cache.patterns), solid_pattern_cache.size); i++) { free (solid_pattern_cache.patterns[i]); solid_pattern_cache.patterns[i] = NULL; } @@ -336,10 +327,8 @@ _cairo_pattern_create_in_error (cairo_status_t status) { cairo_pattern_t *pattern; - pattern = _cairo_pattern_create_solid_from_cache (_cairo_stock_color (CAIRO_STOCK_BLACK)); - if (cairo_pattern_status (pattern)) - return pattern; - + pattern = _cairo_pattern_create_solid (_cairo_stock_color (CAIRO_STOCK_BLACK)); + /* no-op on a pattern already in error i.e the _cairo_pattern_nil */ _cairo_pattern_set_error (pattern, status); return pattern; @@ -644,7 +633,7 @@ cairo_pattern_destroy (cairo_pattern_t *pattern) CAIRO_MUTEX_LOCK (_cairo_pattern_solid_cache_lock); i = solid_pattern_cache.size++ % - ARRAY_LEN (solid_pattern_cache.patterns); + ARRAY_LENGTH (solid_pattern_cache.patterns); /* swap an old pattern for this 'cache-hot' pattern */ if (solid_pattern_cache.patterns[i]) free (solid_pattern_cache.patterns[i]); @@ -737,7 +726,7 @@ _cairo_pattern_gradient_grow (cairo_gradient_pattern_t *pattern) { pixman_gradient_stop_t *new_stops; int old_size = pattern->stops_size; - int embedded_size = ARRAY_LEN (pattern->stops_embedded); + int embedded_size = ARRAY_LENGTH (pattern->stops_embedded); int new_size = 2 * MAX (old_size, 4); /* we have a local buffer at pattern->stops_embedded. try to fulfill the request @@ -943,10 +932,18 @@ void cairo_pattern_set_matrix (cairo_pattern_t *pattern, const cairo_matrix_t *matrix) { + cairo_matrix_t inverse; + cairo_status_t status; + if (pattern->status) return; pattern->matrix = *matrix; + + inverse = *matrix; + status = cairo_matrix_invert (&inverse); + if (status) + _cairo_pattern_set_error (pattern, status); } slim_hidden_def (cairo_pattern_set_matrix); @@ -1191,7 +1188,11 @@ _cairo_pattern_acquire_surface_for_gradient (cairo_gradient_pattern_t *pattern, pixman_image_set_filter (pixman_image, PIXMAN_FILTER_BILINEAR); _cairo_matrix_to_pixman_matrix (&pattern->base.matrix, &pixman_transform); - pixman_image_set_transform (pixman_image, &pixman_transform); + if (pixman_image_set_transform (pixman_image, &pixman_transform)) { + cairo_surface_destroy (&image->base); + pixman_image_destroy (pixman_image); + return CAIRO_STATUS_NO_MEMORY; + } switch (pattern->base.extend) { case CAIRO_EXTEND_NONE: @@ -1755,7 +1756,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 a5b18c56b..38b447e8a 100644 --- a/src/cairo-pdf-surface.c +++ b/src/cairo-pdf-surface.c @@ -151,10 +151,10 @@ _cairo_pdf_surface_open_stream (cairo_pdf_surface_t *surface, cairo_bool_t compressed, const char *fmt, ...) CAIRO_PRINTF_FORMAT(3, 4); -static void +static cairo_status_t _cairo_pdf_surface_close_stream (cairo_pdf_surface_t *surface); -static void +static cairo_status_t _cairo_pdf_surface_add_stream (cairo_pdf_surface_t *surface, cairo_pdf_resource_t stream); @@ -210,26 +210,26 @@ _cairo_pdf_surface_update_object (cairo_pdf_surface_t *surface, object->offset = _cairo_output_stream_get_position (surface->output); } -static void +static cairo_status_t _cairo_pdf_surface_add_stream (cairo_pdf_surface_t *surface, cairo_pdf_resource_t stream) { - /* XXX: Should be checking the return value here. */ - _cairo_array_append (&surface->streams, &stream); + return _cairo_array_append (&surface->streams, &stream); } -static void +static cairo_status_t _cairo_pdf_surface_add_pattern (cairo_pdf_surface_t *surface, cairo_pdf_resource_t pattern) { - /* XXX: Should be checking the return value here. */ - _cairo_array_append (&surface->patterns, &pattern); + return _cairo_array_append (&surface->patterns, &pattern); } -static cairo_pdf_resource_t -_cairo_pdf_surface_add_alpha (cairo_pdf_surface_t *surface, double alpha) +static cairo_status_t +_cairo_pdf_surface_add_alpha (cairo_pdf_surface_t *surface, + double alpha, + cairo_pdf_resource_t *resource) { - cairo_pdf_resource_t resource; + cairo_status_t status; int num_alphas, i; double other; @@ -237,16 +237,18 @@ _cairo_pdf_surface_add_alpha (cairo_pdf_surface_t *surface, double alpha) for (i = 0; i < num_alphas; i++) { _cairo_array_copy_element (&surface->alphas, i, &other); if (alpha == other) { - resource.id = i; - return resource; + resource->id = i; + return CAIRO_STATUS_SUCCESS; } } - /* XXX: Should be checking the return value here. */ - _cairo_array_append (&surface->alphas, &alpha); + status = _cairo_array_append (&surface->alphas, &alpha); + if (status) + return status; - resource.id = _cairo_array_num_elements (&surface->alphas) - 1; - return resource; + resource->id = _cairo_array_num_elements (&surface->alphas) - 1; + + return CAIRO_STATUS_SUCCESS; } static cairo_surface_t * @@ -502,16 +504,17 @@ _cairo_pdf_surface_open_stream (cairo_pdf_surface_t *surface, return surface->current_stream.self; } -static void +static cairo_status_t _cairo_pdf_surface_close_stream (cairo_pdf_surface_t *surface) { + cairo_status_t status = CAIRO_STATUS_SUCCESS; long length; if (! surface->current_stream.active) - return; + return CAIRO_STATUS_SUCCESS; if (surface->current_stream.compressed) { - _cairo_output_stream_destroy (surface->output); + status = _cairo_output_stream_destroy (surface->output); surface->output = surface->current_stream.old_output; _cairo_output_stream_printf (surface->output, "\r\n"); @@ -533,17 +536,19 @@ _cairo_pdf_surface_close_stream (cairo_pdf_surface_t *surface) length); surface->current_stream.active = FALSE; + + return status; } static cairo_status_t _cairo_pdf_surface_finish (void *abstract_surface) { - cairo_status_t status; + cairo_status_t status, status2; cairo_pdf_surface_t *surface = abstract_surface; long offset; cairo_pdf_resource_t info, catalog; - _cairo_pdf_surface_close_stream (surface); + status = _cairo_pdf_surface_close_stream (surface); _cairo_pdf_surface_emit_font_subsets (surface); @@ -569,7 +574,9 @@ _cairo_pdf_surface_finish (void *abstract_surface) "%%%%EOF\r\n", offset); - status = _cairo_output_stream_destroy (surface->output); + status2 = _cairo_output_stream_destroy (surface->output); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; _cairo_array_fini (&surface->objects); _cairo_array_fini (&surface->pages); @@ -588,13 +595,13 @@ _cairo_pdf_surface_finish (void *abstract_surface) return status; } -static void +static cairo_status_t _cairo_pdf_surface_pause_content_stream (cairo_pdf_surface_t *surface) { - _cairo_pdf_surface_close_stream (surface); + return _cairo_pdf_surface_close_stream (surface); } -static void +static cairo_status_t _cairo_pdf_surface_resume_content_stream (cairo_pdf_surface_t *surface) { cairo_pdf_resource_t stream; @@ -607,12 +614,13 @@ _cairo_pdf_surface_resume_content_stream (cairo_pdf_surface_t *surface) surface->width, surface->height); - _cairo_pdf_surface_add_stream (surface, stream); + return _cairo_pdf_surface_add_stream (surface, stream); } static cairo_int_status_t _cairo_pdf_surface_start_page (void *abstract_surface) { + cairo_status_t status; cairo_pdf_surface_t *surface = abstract_surface; cairo_pdf_resource_t stream; @@ -624,7 +632,9 @@ _cairo_pdf_surface_start_page (void *abstract_surface) surface->width, surface->height); - _cairo_pdf_surface_add_stream (surface, stream); + status = _cairo_pdf_surface_add_stream (surface, stream); + if (status) + return status; _cairo_output_stream_printf (surface->output, "1 0 0 -1 0 %f cm\r\n", @@ -716,7 +726,7 @@ _cairo_pdf_surface_emit_smask (cairo_pdf_surface_t *surface, image->width, image->height); _cairo_output_stream_write (surface->output, alpha_compressed, alpha_compressed_size); _cairo_output_stream_printf (surface->output, "\r\n"); - _cairo_pdf_surface_close_stream (surface); + status = _cairo_pdf_surface_close_stream (surface); free (alpha_compressed); CLEANUP_ALPHA: @@ -830,7 +840,7 @@ _cairo_pdf_surface_emit_image (cairo_pdf_surface_t *surface, _cairo_output_stream_write (surface->output, compressed, compressed_size); _cairo_output_stream_printf (surface->output, "\r\n"); - _cairo_pdf_surface_close_stream (surface); + status = _cairo_pdf_surface_close_stream (surface); CLEANUP_COMPRESSED: free (compressed); @@ -844,9 +854,14 @@ static cairo_status_t _cairo_pdf_surface_emit_solid_pattern (cairo_pdf_surface_t *surface, cairo_solid_pattern_t *pattern) { + cairo_status_t status; cairo_pdf_resource_t alpha; - alpha = _cairo_pdf_surface_add_alpha (surface, pattern->color.alpha); + status = _cairo_pdf_surface_add_alpha (surface, + pattern->color.alpha, + &alpha); + if (status) + return status; /* With some work, we could separate the stroking * or non-stroking color here as actually needed. */ @@ -883,7 +898,9 @@ _cairo_pdf_surface_emit_surface_pattern (cairo_pdf_surface_t *surface, /* XXX: Should do something clever here for PDF source surfaces ? */ - _cairo_pdf_surface_pause_content_stream (surface); + status = _cairo_pdf_surface_pause_content_stream (surface); + if (status) + return status; status = _cairo_pattern_acquire_surface ((cairo_pattern_t *)pattern, (cairo_surface_t *)surface, @@ -900,7 +917,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 +993,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); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); cairo_matrix_init_identity (&pdf_p2d); cairo_matrix_translate (&pdf_p2d, 0.0, surface_extents.height); @@ -1006,13 +1027,22 @@ _cairo_pdf_surface_emit_surface_pattern (cairo_pdf_surface_t *surface, image->width, image->height, image_resource.id); - _cairo_pdf_surface_close_stream (surface); + status = _cairo_pdf_surface_close_stream (surface); + if (status) + goto BAIL; + + status = _cairo_pdf_surface_resume_content_stream (surface); + if (status) + goto BAIL; - _cairo_pdf_surface_resume_content_stream (surface); + status = _cairo_pdf_surface_add_pattern (surface, stream); + if (status) + goto BAIL; - _cairo_pdf_surface_add_pattern (surface, stream); + status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha); + if (status) + goto BAIL; - alpha = _cairo_pdf_surface_add_alpha (surface, 1.0); /* With some work, we could separate the stroking * or non-stroking pattern here as actually needed. */ _cairo_output_stream_printf (surface->output, @@ -1192,7 +1222,9 @@ _cairo_pdf_surface_emit_linear_pattern (cairo_pdf_surface_t *surface, cairo_line cairo_matrix_t p2u; cairo_status_t status; - _cairo_pdf_surface_pause_content_stream (surface); + status = _cairo_pdf_surface_pause_content_stream (surface); + if (status) + return status; function = _cairo_pdf_surface_emit_pattern_stops (surface, &pattern->base); if (function.id == 0) @@ -1230,9 +1262,13 @@ _cairo_pdf_surface_emit_linear_pattern (cairo_pdf_surface_t *surface, cairo_line x0, y0, x1, y1, function.id); - _cairo_pdf_surface_add_pattern (surface, pattern_resource); + status = _cairo_pdf_surface_add_pattern (surface, pattern_resource); + if (status) + return status; - alpha = _cairo_pdf_surface_add_alpha (surface, 1.0); + status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha); + if (status) + return status; /* Use pattern */ /* With some work, we could separate the stroking @@ -1245,9 +1281,7 @@ _cairo_pdf_surface_emit_linear_pattern (cairo_pdf_surface_t *surface, cairo_line pattern_resource.id, alpha.id); - _cairo_pdf_surface_resume_content_stream (surface); - - return CAIRO_STATUS_SUCCESS; + return _cairo_pdf_surface_resume_content_stream (surface); } static cairo_status_t @@ -1256,15 +1290,20 @@ _cairo_pdf_surface_emit_radial_pattern (cairo_pdf_surface_t *surface, cairo_radi cairo_pdf_resource_t function, pattern_resource, alpha; double x0, y0, x1, y1, r0, r1; cairo_matrix_t p2u; + cairo_status_t status; - _cairo_pdf_surface_pause_content_stream (surface); + status = _cairo_pdf_surface_pause_content_stream (surface); + if (status) + return status; function = _cairo_pdf_surface_emit_pattern_stops (surface, &pattern->base); if (function.id == 0) 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); @@ -1306,9 +1345,13 @@ _cairo_pdf_surface_emit_radial_pattern (cairo_pdf_surface_t *surface, cairo_radi x0, y0, r0, x1, y1, r1, function.id); - _cairo_pdf_surface_add_pattern (surface, pattern_resource); + status = _cairo_pdf_surface_add_pattern (surface, pattern_resource); + if (status) + return status; - alpha = _cairo_pdf_surface_add_alpha (surface, 1.0); + status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha); + if (status) + return status; /* Use pattern */ /* With some work, we could separate the stroking @@ -1321,9 +1364,7 @@ _cairo_pdf_surface_emit_radial_pattern (cairo_pdf_surface_t *surface, cairo_radi pattern_resource.id, alpha.id); - _cairo_pdf_surface_resume_content_stream (surface); - - return CAIRO_STATUS_SUCCESS; + return _cairo_pdf_surface_resume_content_stream (surface); } static cairo_status_t @@ -1642,12 +1683,13 @@ _cairo_pdf_surface_write_pages (cairo_pdf_surface_t *surface) } static cairo_pdf_resource_t -_cairo_pdf_surface_emit_toUnicode_stream (cairo_pdf_surface_t *surface, - cairo_scaled_font_subset_t *font_subset) +_cairo_pdf_surface_emit_to_unicode_stream (cairo_pdf_surface_t *surface, + cairo_scaled_font_subset_t *font_subset) { const cairo_scaled_font_backend_t *backend; cairo_pdf_resource_t stream; unsigned int i; + cairo_status_t status; if (font_subset->to_unicode == NULL) { stream.id = 0; @@ -1715,7 +1757,9 @@ _cairo_pdf_surface_emit_toUnicode_stream (cairo_pdf_surface_t *surface, "end\r\n" "end\r\n"); - _cairo_pdf_surface_close_stream (surface); + status = _cairo_pdf_surface_close_stream (surface); + if (status) + stream.id = 0; return stream; } @@ -1762,7 +1806,7 @@ _cairo_pdf_surface_emit_cff_font_subset (cairo_pdf_surface_t *surface, "endobj\r\n"); free (compressed); - to_unicode_stream = _cairo_pdf_surface_emit_toUnicode_stream (surface, font_subset); + to_unicode_stream = _cairo_pdf_surface_emit_to_unicode_stream (surface, font_subset); descriptor = _cairo_pdf_surface_new_object (surface); _cairo_output_stream_printf (surface->output, @@ -1825,11 +1869,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 @@ -1871,7 +1915,7 @@ _cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t *surface, "endobj\r\n"); free (compressed); - to_unicode_stream = _cairo_pdf_surface_emit_toUnicode_stream (surface, font_subset); + to_unicode_stream = _cairo_pdf_surface_emit_to_unicode_stream (surface, font_subset); descriptor = _cairo_pdf_surface_new_object (surface); _cairo_output_stream_printf (surface->output, @@ -1934,9 +1978,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 @@ -2024,7 +2066,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t *surface, "endobj\r\n"); free (compressed); - to_unicode_stream = _cairo_pdf_surface_emit_toUnicode_stream (surface, font_subset); + to_unicode_stream = _cairo_pdf_surface_emit_to_unicode_stream (surface, font_subset); descriptor = _cairo_pdf_surface_new_object (surface); _cairo_output_stream_printf (surface->output, @@ -2105,11 +2147,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 @@ -2153,9 +2195,7 @@ _cairo_pdf_surface_emit_outline_glyph (cairo_pdf_surface_t *surface, _cairo_output_stream_printf (surface->output, " f"); - _cairo_pdf_surface_close_stream (surface); - - return CAIRO_STATUS_SUCCESS; + return _cairo_pdf_surface_close_stream (surface); } static cairo_int_status_t @@ -2232,7 +2272,7 @@ _cairo_pdf_surface_emit_bitmap_glyph (cairo_pdf_surface_t *surface, _cairo_output_stream_printf (surface->output, "\r\nEI\r\n"); - _cairo_pdf_surface_close_stream (surface); + status = _cairo_pdf_surface_close_stream (surface); if (image != scaled_glyph->surface) cairo_surface_destroy (&image->base); @@ -2270,6 +2310,7 @@ static cairo_status_t _cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t *surface, cairo_scaled_font_subset_t *font_subset) { + cairo_status_t status; cairo_pdf_resource_t *glyphs, encoding, char_procs, subset_resource, to_unicode_stream; cairo_pdf_font_t font; cairo_matrix_t matrix; @@ -2342,11 +2383,13 @@ _cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t *surface, free (glyphs); - to_unicode_stream = _cairo_pdf_surface_emit_toUnicode_stream (surface, font_subset); + to_unicode_stream = _cairo_pdf_surface_emit_to_unicode_stream (surface, font_subset); subset_resource = _cairo_pdf_surface_new_object (surface); matrix = font_subset->scaled_font->scale; - cairo_matrix_invert (&matrix); + status = cairo_matrix_invert (&matrix); + /* _cairo_scaled_font_init ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); _cairo_output_stream_printf (surface->output, "%d 0 obj\r\n" "<< /Type /Font\r\n" @@ -2390,9 +2433,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 @@ -2512,7 +2553,9 @@ _cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface) surface->has_clip = FALSE; } - _cairo_pdf_surface_close_stream (surface); + status = _cairo_pdf_surface_close_stream (surface); + if (status) + return status; page = _cairo_pdf_surface_new_object (surface); _cairo_output_stream_printf (surface->output, diff --git a/src/cairo-pen.c b/src/cairo-pen.c index 1af8c36a1..ec9eb7ac4 100644 --- a/src/cairo-pen.c +++ b/src/cairo-pen.c @@ -45,15 +45,13 @@ _cairo_pen_compute_slopes (cairo_pen_t *pen); static cairo_status_t _cairo_pen_stroke_spline_half (cairo_pen_t *pen, cairo_spline_t *spline, cairo_direction_t dir, cairo_polygon_t *polygon); -cairo_status_t +void _cairo_pen_init_empty (cairo_pen_t *pen) { pen->radius = 0; pen->tolerance = 0; pen->vertices = NULL; pen->num_vertices = 0; - - return CAIRO_STATUS_SUCCESS; } cairo_status_t @@ -135,6 +133,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 +149,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,15 +389,18 @@ _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) { hull_point.x = point[i].x + pen->vertices[active].point.x; hull_point.y = point[i].y + pen->vertices[active].point.y; - status = _cairo_polygon_line_to (polygon, &hull_point); - if (status) - return status; + + _cairo_polygon_line_to (polygon, &hull_point); if (i + step == stop) slope = final_slope; @@ -437,19 +441,24 @@ _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_status (&polygon); + if (status) + goto BAIL; + + status = _cairo_bentley_ottmann_tessellate_polygon (traps, &polygon, CAIRO_FILL_RULE_WINDING); +BAIL: _cairo_polygon_fini (&polygon); - return CAIRO_STATUS_SUCCESS; + return status; } diff --git a/src/cairo-polygon.c b/src/cairo-polygon.c index bba9e9381..e9fc78b79 100644 --- a/src/cairo-polygon.c +++ b/src/cairo-polygon.c @@ -44,6 +44,8 @@ _cairo_polygon_grow (cairo_polygon_t *polygon); void _cairo_polygon_init (cairo_polygon_t *polygon) { + polygon->status = CAIRO_STATUS_SUCCESS; + polygon->num_edges = 0; polygon->edges_size = 0; @@ -65,13 +67,19 @@ _cairo_polygon_fini (cairo_polygon_t *polygon) polygon->has_current_point = FALSE; } +cairo_status_t +_cairo_polygon_status (cairo_polygon_t *polygon) +{ + return polygon->status; +} + /* make room for at least one more edge */ static cairo_status_t _cairo_polygon_grow (cairo_polygon_t *polygon) { cairo_edge_t *new_edges; int old_size = polygon->edges_size; - int embedded_size = ARRAY_LEN (polygon->edges_embedded); + int embedded_size = ARRAY_LENGTH (polygon->edges_embedded); int new_size = 2 * MAX (old_size, 16); /* we have a local buffer at polygon->edges_embedded. try to fulfill the request @@ -102,22 +110,22 @@ _cairo_polygon_grow (cairo_polygon_t *polygon) return CAIRO_STATUS_SUCCESS; } -cairo_status_t +void _cairo_polygon_add_edge (cairo_polygon_t *polygon, cairo_point_t *p1, cairo_point_t *p2) { - cairo_status_t status; cairo_edge_t *edge; + if (polygon->status) + return; + /* drop horizontal edges */ - if (p1->y == p2->y) { + if (p1->y == p2->y) goto DONE; - } if (polygon->num_edges >= polygon->edges_size) { - status = _cairo_polygon_grow (polygon); - if (status) { - return status; - } + polygon->status = _cairo_polygon_grow (polygon); + if (polygon->status) + return; } edge = &polygon->edges[polygon->num_edges]; @@ -135,49 +143,45 @@ _cairo_polygon_add_edge (cairo_polygon_t *polygon, cairo_point_t *p1, cairo_poin DONE: _cairo_polygon_move_to (polygon, p2); - - return CAIRO_STATUS_SUCCESS; } -cairo_status_t +void _cairo_polygon_move_to (cairo_polygon_t *polygon, cairo_point_t *point) { + if (polygon->status) + return; + if (! polygon->has_current_point) polygon->first_point = *point; + polygon->current_point = *point; polygon->has_current_point = TRUE; - - return CAIRO_STATUS_SUCCESS; } -cairo_status_t +void _cairo_polygon_line_to (cairo_polygon_t *polygon, cairo_point_t *point) { - cairo_status_t status = CAIRO_STATUS_SUCCESS; + if (polygon->status) + return; if (polygon->has_current_point) { - status = _cairo_polygon_add_edge (polygon, &polygon->current_point, point); + _cairo_polygon_add_edge (polygon, &polygon->current_point, point); } else { _cairo_polygon_move_to (polygon, point); } - - return status; } -cairo_status_t +void _cairo_polygon_close (cairo_polygon_t *polygon) { - cairo_status_t status; + if (polygon->status) + return; if (polygon->has_current_point) { - status = _cairo_polygon_add_edge (polygon, - &polygon->current_point, - &polygon->first_point); - if (status) - return status; + _cairo_polygon_add_edge (polygon, + &polygon->current_point, + &polygon->first_point); polygon->has_current_point = FALSE; } - - return CAIRO_STATUS_SUCCESS; } diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index 52efc8316..d725c5390 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -297,7 +297,7 @@ _cairo_ps_surface_emit_path (cairo_ps_surface_t *surface, cairo_line_cap_t line_cap) { cairo_output_stream_t *word_wrap; - cairo_status_t status; + cairo_status_t status, status2; ps_path_info_t path_info; word_wrap = _word_wrap_stream_create (stream, 79); @@ -315,7 +315,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; } @@ -666,6 +668,7 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t *surface, { + cairo_status_t status; cairo_matrix_t matrix; unsigned int i; @@ -678,7 +681,9 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t *surface, font_subset->subset_id); matrix = font_subset->scaled_font->scale; - cairo_matrix_invert (&matrix); + status = cairo_matrix_invert (&matrix); + /* _cairo_scaled_font_init ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); _cairo_output_stream_printf (surface->final_stream, "\t/FontType\t3\n" "\t/FontMatrix\t[%f %f %f %f 0 0]\n" @@ -834,7 +839,8 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream, &cairo_ps_surface_paginated_backend); CLEANUP_OUTPUT_STREAM: - _cairo_output_stream_destroy (surface->stream); + status = _cairo_output_stream_destroy (surface->stream); + /* Ignore status---we're already on a failure path. */ CLEANUP_TMPFILE: fclose (surface->tmpfile); CLEANUP_SURFACE: @@ -1201,7 +1207,7 @@ cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface) static cairo_status_t _cairo_ps_surface_finish (void *abstract_surface) { - cairo_status_t status; + cairo_status_t status, status2; cairo_ps_surface_t *surface = abstract_surface; int i, num_comments; char **comments; @@ -1214,16 +1220,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); @@ -1562,7 +1565,7 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t *surface, cairo_image_surface_t *image, const char *name) { - cairo_status_t status; + cairo_status_t status, status2; unsigned char *rgb, *compressed; unsigned long rgb_size, compressed_size; cairo_surface_t *opaque; @@ -1588,20 +1591,29 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t *surface, _cairo_pattern_init_for_surface (&pattern.surface, &image->base); - _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); + status = _cairo_surface_fill_rectangle (opaque, + CAIRO_OPERATOR_SOURCE, + CAIRO_COLOR_WHITE, + 0, 0, + image->width, image->height); + if (status) { + _cairo_pattern_fini (&pattern.base); + goto bail0; + } + + status = _cairo_surface_composite (CAIRO_OPERATOR_OVER, + &pattern.base, + NULL, + opaque, + 0, 0, + 0, 0, + 0, 0, + image->width, + image->height); + if (status) { + _cairo_pattern_fini (&pattern.base); + goto bail0; + } _cairo_pattern_fini (&pattern.base); opaque_image = (cairo_image_surface_t *) opaque; @@ -1646,8 +1658,12 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t *surface, _cairo_output_stream_write (base85_stream, compressed, compressed_size); - _cairo_output_stream_destroy (base85_stream); - _cairo_output_stream_destroy (string_array_stream); + status = _cairo_output_stream_destroy (base85_stream); + status2 = _cairo_output_stream_destroy (string_array_stream); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + if (status) + goto bail3; _cairo_output_stream_printf (surface->stream, "] def\n"); @@ -1679,6 +1695,7 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t *surface, status = CAIRO_STATUS_SUCCESS; + bail3: free (compressed); bail2: free (rgb); @@ -1705,19 +1722,26 @@ _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) { + cairo_status_t status; double bbox_width, bbox_height; double xstep, ystep; cairo_matrix_t inverse = pattern->base.matrix; - cairo_matrix_invert (&inverse); + status = cairo_matrix_invert (&inverse); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); 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 +1829,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,12 +1847,13 @@ _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) { /* 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. */ + cairo_status_t status; switch (pattern->type) { case CAIRO_PATTERN_TYPE_SOLID: @@ -1834,7 +1861,10 @@ _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); + if (status) + return status; break; case CAIRO_PATTERN_TYPE_LINEAR: @@ -1845,6 +1875,8 @@ _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 CAIRO_STATUS_SUCCESS; } static cairo_int_status_t @@ -1930,6 +1962,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,11 +1980,19 @@ _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); + status = _cairo_ps_surface_emit_pattern (surface, source); + if (status) + return status; _cairo_output_stream_printf (stream, "%d %d M\n", extents.x, extents.y); @@ -1965,6 +2006,7 @@ _cairo_ps_surface_paint (void *abstract_surface, extents.x, extents.y + extents.height); _cairo_output_stream_printf (stream, "P F\n"); + return CAIRO_STATUS_SUCCESS; } diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c index 963c06092..b582539c2 100644 --- a/src/cairo-scaled-font.c +++ b/src/cairo-scaled-font.c @@ -153,6 +153,7 @@ cairo_scaled_font_status (cairo_scaled_font_t *scaled_font) { return scaled_font->status; } +slim_hidden_def (cairo_scaled_font_status); /* Here we keep a unique mapping from * cairo_font_face_t/matrix/ctm/options => cairo_scaled_font_t. @@ -211,6 +212,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; @@ -350,23 +352,36 @@ _cairo_scaled_font_init (cairo_scaled_font_t *scaled_font, const cairo_font_options_t *options, const cairo_scaled_font_backend_t *backend) { - scaled_font->ref_count = 1; - - _cairo_user_data_array_init (&scaled_font->user_data); + cairo_matrix_t inverse; + cairo_status_t status; + /* Initialize scaled_font->scale early for easier bail out on an + * invalid matrix. */ _cairo_scaled_font_init_key (scaled_font, font_face, font_matrix, ctm, options); - cairo_font_face_reference (font_face); - cairo_matrix_multiply (&scaled_font->scale, &scaled_font->font_matrix, &scaled_font->ctm); - CAIRO_MUTEX_INIT (&scaled_font->mutex); + inverse = scaled_font->scale; + status = cairo_matrix_invert (&inverse); + if (status) + return status; + scaled_font->glyphs = _cairo_cache_create (_cairo_scaled_glyph_keys_equal, _cairo_scaled_glyph_destroy, max_glyphs_cached_per_font); + if (scaled_font->glyphs == NULL) + return CAIRO_STATUS_NO_MEMORY; + + scaled_font->ref_count = 1; + + _cairo_user_data_array_init (&scaled_font->user_data); + + cairo_font_face_reference (font_face); + + CAIRO_MUTEX_INIT (&scaled_font->mutex); scaled_font->surface_backend = NULL; scaled_font->surface_private = NULL; @@ -474,7 +489,7 @@ cairo_scaled_font_create (cairo_font_face_t *font_face, font_map = _cairo_scaled_font_map_lock (); if (font_map == NULL) - return NULL; + return (cairo_scaled_font_t *)&_cairo_scaled_font_nil; _cairo_scaled_font_init_key (&key, font_face, font_matrix, ctm, options); @@ -513,7 +528,7 @@ cairo_scaled_font_create (cairo_font_face_t *font_face, ctm, options, &scaled_font); if (status) { _cairo_scaled_font_map_unlock (); - return NULL; + return (cairo_scaled_font_t *)&_cairo_scaled_font_nil; } status = _cairo_hash_table_insert (font_map->hash_table, @@ -526,7 +541,7 @@ cairo_scaled_font_create (cairo_font_face_t *font_face, * hash table. */ _cairo_scaled_font_fini (scaled_font); free (scaled_font); - return NULL; + return (cairo_scaled_font_t *)&_cairo_scaled_font_nil; } } @@ -1174,6 +1189,42 @@ _scaled_glyph_path_close_path (void *abstract_closure) return _cairo_path_fixed_close_path (closure->path); } +/* Add a single-device-unit rectangle to a path. */ +static cairo_status_t +_add_unit_rectangle_to_path (cairo_path_fixed_t *path, int x, int y) +{ + cairo_status_t status; + + status = _cairo_path_fixed_move_to (path, + _cairo_fixed_from_int (x), + _cairo_fixed_from_int (y)); + if (status) + return status; + + status = _cairo_path_fixed_rel_line_to (path, + _cairo_fixed_from_int (1), + _cairo_fixed_from_int (0)); + if (status) + return status; + + status = _cairo_path_fixed_rel_line_to (path, + _cairo_fixed_from_int (0), + _cairo_fixed_from_int (1)); + if (status) + return status; + + status = _cairo_path_fixed_rel_line_to (path, + _cairo_fixed_from_int (-1), + _cairo_fixed_from_int (0)); + if (status) + return status; + + status = _cairo_path_fixed_close_path (path); + if (status) + return status; + + return CAIRO_STATUS_SUCCESS; +} /** * _trace_mask_to_path: @@ -1196,6 +1247,7 @@ static cairo_status_t _trace_mask_to_path (cairo_image_surface_t *mask, cairo_path_fixed_t *path) { + cairo_status_t status; cairo_image_surface_t *a1_mask; unsigned char *row, *byte_ptr, byte; int rows, cols, bytes_per_row; @@ -1218,19 +1270,10 @@ _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 = _add_unit_rectangle_to_path (path, + x + xoff, y + yoff); + if (status) + return status; } } } diff --git a/src/cairo-skiplist.c b/src/cairo-skiplist.c index 2d2fbb002..72ca6ce15 100644 --- a/src/cairo-skiplist.c +++ b/src/cairo-skiplist.c @@ -355,6 +355,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); diff --git a/src/cairo-spline.c b/src/cairo-spline.c index 42151aa5f..bf8777003 100644 --- a/src/cairo-spline.c +++ b/src/cairo-spline.c @@ -80,9 +80,9 @@ _cairo_spline_init (cairo_spline_t *spline, else _cairo_slope_init (&spline->final_slope, &spline->a, &spline->d); + spline->points = spline->points_embedded; + spline->points_size = ARRAY_LENGTH (spline->points_embedded); spline->num_points = 0; - spline->points_size = 0; - spline->points = NULL; return CAIRO_STATUS_SUCCESS; } @@ -90,11 +90,11 @@ _cairo_spline_init (cairo_spline_t *spline, void _cairo_spline_fini (cairo_spline_t *spline) { - if (spline->points && spline->points != spline->points_embedded) + if (spline->points != spline->points_embedded) free (spline->points); - spline->points = NULL; - spline->points_size = 0; + spline->points = spline->points_embedded; + spline->points_size = ARRAY_LENGTH (spline->points_embedded); spline->num_points = 0; } @@ -104,17 +104,8 @@ _cairo_spline_grow (cairo_spline_t *spline) { cairo_point_t *new_points; int old_size = spline->points_size; - int embedded_size = ARRAY_LEN (spline->points_embedded); int new_size = 2 * MAX (old_size, 16); - /* we have a local buffer at spline->points_embedded. try to fulfill the request - * from there. */ - if (old_size < embedded_size) { - spline->points = spline->points_embedded; - spline->points_size = embedded_size; - return CAIRO_STATUS_SUCCESS; - } - assert (spline->num_points <= spline->points_size); if (spline->points == spline->points_embedded) { @@ -284,9 +275,8 @@ _cairo_spline_decompose (cairo_spline_t *spline, double tolerance) { cairo_status_t status; - if (spline->points_size) { - _cairo_spline_fini (spline); - } + /* reset the spline, but keep the buffer */ + spline->num_points = 0; status = _cairo_spline_decompose_into (spline, tolerance * tolerance, spline); if (status) diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c index 581d31216..a504826b4 100644 --- a/src/cairo-surface-fallback.c +++ b/src/cairo-surface-fallback.c @@ -454,8 +454,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); @@ -992,17 +995,21 @@ _cairo_surface_fallback_snapshot (cairo_surface_t *surface) _cairo_pattern_init_for_surface (&pattern.surface, &image->base); - _cairo_surface_composite (CAIRO_OPERATOR_SOURCE, - &pattern.base, - NULL, - snapshot, - 0, 0, - 0, 0, - 0, 0, - image->width, - image->height); + status = _cairo_surface_composite (CAIRO_OPERATOR_SOURCE, + &pattern.base, + NULL, + snapshot, + 0, 0, + 0, 0, + 0, 0, + image->width, + image->height); _cairo_pattern_fini (&pattern.base); + if (status) { + cairo_surface_destroy (snapshot); + return (cairo_surface_t *) &_cairo_surface_nil; + } _cairo_surface_release_source_image (surface, image, &image_extra); @@ -1171,13 +1178,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-surface.c b/src/cairo-surface.c index 93d4f4689..c6f64eb8e 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -1180,7 +1180,7 @@ _cairo_surface_fill_region (cairo_surface_t *surface, return CAIRO_STATUS_SUCCESS; rects = stack_rects; - if (num_rects > ARRAY_LEN (stack_rects)) { + if (num_rects > ARRAY_LENGTH (stack_rects)) { rects = malloc (sizeof (cairo_rectangle_int16_t) * num_rects); if (!rects) return CAIRO_STATUS_NO_MEMORY; @@ -1434,10 +1434,7 @@ _cairo_surface_composite_trapezoids (cairo_operator_t op, traps, num_traps); } -/* _copy_page and _show_page are unique among _cairo_surface functions - * in that they will actually return CAIRO_INT_STATUS_UNSUPPORTED - * rather than performing any fallbacks. */ -cairo_int_status_t +cairo_status_t _cairo_surface_copy_page (cairo_surface_t *surface) { assert (! surface->is_snapshot); @@ -1448,16 +1445,14 @@ _cairo_surface_copy_page (cairo_surface_t *surface) if (surface->finished) return CAIRO_STATUS_SURFACE_FINISHED; + /* It's fine if some backends don't implement copy_page */ if (surface->backend->copy_page == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; + return CAIRO_STATUS_SUCCESS; return surface->backend->copy_page (surface); } -/* _show_page and _copy_page are unique among _cairo_surface functions - * in that they will actually return CAIRO_INT_STATUS_UNSUPPORTED - * rather than performing any fallbacks. */ -cairo_int_status_t +cairo_status_t _cairo_surface_show_page (cairo_surface_t *surface) { assert (! surface->is_snapshot); @@ -1468,8 +1463,9 @@ _cairo_surface_show_page (cairo_surface_t *surface) if (surface->finished) return CAIRO_STATUS_SURFACE_FINISHED; + /* It's fine if some backends don't implement show_page */ if (surface->backend->show_page == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; + return CAIRO_STATUS_SUCCESS; return surface->backend->show_page (surface); } diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c index 703017a9a..3fb6b7965 100644 --- a/src/cairo-svg-surface.c +++ b/src/cairo-svg-surface.c @@ -59,7 +59,7 @@ static const cairo_svg_version_t _cairo_svg_versions[] = CAIRO_SVG_VERSION_1_2 }; -#define CAIRO_SVG_VERSION_LAST ARRAY_LEN (_cairo_svg_versions) +#define CAIRO_SVG_VERSION_LAST ARRAY_LENGTH (_cairo_svg_versions) static cairo_bool_t _cairo_svg_version_has_page_set_support (cairo_svg_version_t version) @@ -447,7 +447,8 @@ _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); + if (_cairo_array_append (&surface->page_set, &page) != CAIRO_STATUS_SUCCESS) + return NULL; return _cairo_array_index (&surface->page_set, surface->page_set.num_elements - 1); } @@ -706,14 +707,21 @@ _cairo_svg_document_emit_font_subset (cairo_scaled_font_subset_t *font_subset, } } -static void +static cairo_status_t _cairo_svg_document_emit_font_subsets (cairo_svg_document_t *document) { - _cairo_scaled_font_subsets_foreach_scaled (document->font_subsets, - _cairo_svg_document_emit_font_subset, - document); + cairo_status_t status; + + status = _cairo_scaled_font_subsets_foreach_scaled (document->font_subsets, + _cairo_svg_document_emit_font_subset, + document); + if (status) + return status; + _cairo_scaled_font_subsets_destroy (document->font_subsets); document->font_subsets = NULL; + + return CAIRO_STATUS_SUCCESS; } static cairo_bool_t cairo_svg_force_fallbacks = FALSE; @@ -776,7 +784,7 @@ _cairo_svg_surface_create_similar (void *abstract_src, static cairo_status_t _cairo_svg_surface_finish (void *abstract_surface) { - cairo_status_t status; + cairo_status_t status, status2; cairo_svg_surface_t *surface = abstract_surface; cairo_svg_document_t *document = surface->document; cairo_svg_page_t *page; @@ -787,11 +795,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 +953,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, @@ -978,10 +992,12 @@ _cairo_svg_surface_emit_composite_image_pattern (cairo_output_stream_t *outp return status; } -static int +static cairo_status_t _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document, - cairo_meta_surface_t *surface) + cairo_meta_surface_t *surface, + int *id) { + cairo_status_t status; cairo_surface_t *paginated_surface; cairo_surface_t *svg_surface; cairo_meta_snapshot_t new_snapshot; @@ -991,7 +1007,7 @@ _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document, cairo_meta_surface_t *meta; cairo_meta_snapshot_t *snapshot; unsigned int num_elements; - unsigned int i, id; + unsigned int i; /* search in already emitted meta snapshots */ num_elements = document->meta_snapshots.num_elements; @@ -1000,7 +1016,8 @@ _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document, meta = snapshot->meta; if (meta->commands.num_elements == surface->commands.num_elements && _cairo_array_index (&meta->commands, 0) == _cairo_array_index (&surface->commands, 0)) { - return snapshot->id; + *id = snapshot->id; + return CAIRO_STATUS_SUCCESS; } } @@ -1013,12 +1030,26 @@ _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document, cairo_surface_set_fallback_resolution (paginated_surface, document->owner->x_fallback_resolution, document->owner->y_fallback_resolution); - _cairo_meta_surface_replay ((cairo_surface_t *)meta, paginated_surface); - _cairo_surface_show_page (paginated_surface); + + status = _cairo_meta_surface_replay ((cairo_surface_t *)meta, paginated_surface); + if (status) { + cairo_surface_destroy (&meta->base); + return status; + } + + status = _cairo_surface_show_page (paginated_surface); + if (status) { + cairo_surface_destroy (&meta->base); + return status; + } new_snapshot.meta = meta; new_snapshot.id = ((cairo_svg_surface_t *) svg_surface)->id; - _cairo_array_append (&document->meta_snapshots, &new_snapshot); + status = _cairo_array_append (&document->meta_snapshots, &new_snapshot); + if (status) { + cairo_surface_destroy (&meta->base); + return status; + } if (meta->content == CAIRO_CONTENT_ALPHA) { _cairo_svg_surface_emit_alpha_filter (document); @@ -1051,7 +1082,7 @@ _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document, _cairo_output_stream_printf (document->xml_node_defs, "</g>\n"); - id = new_snapshot.id; + *id = new_snapshot.id; cairo_surface_destroy (paginated_surface); @@ -1062,7 +1093,7 @@ _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document, /* cairo_surface_destroy (svg_surface); */ - return id; + return CAIRO_STATUS_SUCCESS; } static cairo_status_t @@ -1075,14 +1106,19 @@ _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_matrix_t p2u; + cairo_status_t status; int id; - meta_surface = (cairo_meta_surface_t *) pattern->surface; + p2u = pattern->base.matrix; + status = cairo_matrix_invert (&p2u); + if (status) + return status; - id = _cairo_svg_surface_emit_meta_surface (document, meta_surface); + meta_surface = (cairo_meta_surface_t *) pattern->surface; - p2u = pattern->base.matrix; - cairo_matrix_invert (&p2u); + status = _cairo_svg_surface_emit_meta_surface (document, meta_surface, &id); + if (status) + return status; if (pattern_id != invalid_pattern_id) { _cairo_output_stream_printf (output, @@ -1152,7 +1188,7 @@ _cairo_svg_surface_emit_operator (cairo_output_stream_t *output, _cairo_output_stream_printf (output, "comp-op: %s; ", op_str[op]); } -static void +static cairo_status_t _cairo_svg_surface_emit_solid_pattern (cairo_svg_surface_t *surface, cairo_solid_pattern_t *pattern, cairo_output_stream_t *style, @@ -1166,9 +1202,11 @@ _cairo_svg_surface_emit_solid_pattern (cairo_svg_surface_t *surface, pattern->color.green * 100.0, pattern->color.blue * 100.0, pattern->color.alpha); + + return CAIRO_STATUS_SUCCESS; } -static void +static cairo_status_t _cairo_svg_surface_emit_surface_pattern (cairo_svg_surface_t *surface, cairo_surface_pattern_t *pattern, cairo_output_stream_t *style, @@ -1185,6 +1223,8 @@ _cairo_svg_surface_emit_surface_pattern (cairo_svg_surface_t *surface, "%s: url(#pattern%d);", is_stroke ? "color" : "fill", pattern_id); + + return CAIRO_STATUS_SUCCESS; } static void @@ -1366,7 +1406,7 @@ _cairo_svg_surface_emit_pattern_extend (cairo_output_stream_t *output, } } -static void +static cairo_status_t _cairo_svg_surface_emit_linear_pattern (cairo_svg_surface_t *surface, cairo_linear_pattern_t *pattern, cairo_output_stream_t *style, @@ -1375,6 +1415,12 @@ _cairo_svg_surface_emit_linear_pattern (cairo_svg_surface_t *surface, cairo_svg_document_t *document = surface->document; double x0, y0, x1, y1; cairo_matrix_t p2u; + cairo_status_t status; + + p2u = pattern->base.base.matrix; + 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); @@ -1389,8 +1435,6 @@ _cairo_svg_surface_emit_linear_pattern (cairo_svg_surface_t *surface, x0, y0, x1, y1); _cairo_svg_surface_emit_pattern_extend (document->xml_node_defs, &pattern->base.base), - p2u = pattern->base.base.matrix; - cairo_matrix_invert (&p2u); _cairo_svg_surface_emit_transform (document->xml_node_defs, "gradientTransform", ">\n", &p2u); _cairo_svg_surface_emit_pattern_stops (document->xml_node_defs ,&pattern->base, 0.0, FALSE, FALSE); @@ -1404,9 +1448,11 @@ _cairo_svg_surface_emit_linear_pattern (cairo_svg_surface_t *surface, document->linear_pattern_id); document->linear_pattern_id++; + + return CAIRO_STATUS_SUCCESS; } -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, @@ -1418,6 +1464,7 @@ _cairo_svg_surface_emit_radial_pattern (cairo_svg_surface_t *surface, double x0, y0, x1, y1, r0, r1; double fx, fy; cairo_bool_t reverse_stops; + cairo_status_t status; pixman_circle_t *c0, *c1; extend = pattern->base.base.extend; @@ -1440,7 +1487,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,29 +1620,28 @@ _cairo_svg_surface_emit_radial_pattern (cairo_svg_surface_t *surface, document->radial_pattern_id); document->radial_pattern_id++; + + return CAIRO_STATUS_SUCCESS; } -static void +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) { switch (pattern->type) { case CAIRO_PATTERN_TYPE_SOLID: - _cairo_svg_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern, output, is_stroke); - break; + return _cairo_svg_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern, output, is_stroke); case CAIRO_PATTERN_TYPE_SURFACE: - _cairo_svg_surface_emit_surface_pattern (surface, (cairo_surface_pattern_t *) pattern, output, is_stroke); - break; + return _cairo_svg_surface_emit_surface_pattern (surface, (cairo_surface_pattern_t *) pattern, output, is_stroke); case CAIRO_PATTERN_TYPE_LINEAR: - _cairo_svg_surface_emit_linear_pattern (surface, (cairo_linear_pattern_t *) pattern, output, is_stroke); - break; + return _cairo_svg_surface_emit_linear_pattern (surface, (cairo_linear_pattern_t *) pattern, output, is_stroke); case CAIRO_PATTERN_TYPE_RADIAL: - _cairo_svg_surface_emit_radial_pattern (surface, (cairo_radial_pattern_t *) pattern, output, is_stroke); - break; + return _cairo_svg_surface_emit_radial_pattern (surface, (cairo_radial_pattern_t *) pattern, output, is_stroke); } + return CAIRO_STATUS_SUCCESS; } static cairo_int_status_t @@ -1686,6 +1734,7 @@ _cairo_svg_surface_paint (void *abstract_surface, cairo_operator_t op, cairo_pattern_t *source) { + cairo_status_t status; cairo_svg_surface_t *surface = abstract_surface; if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) @@ -1711,8 +1760,12 @@ _cairo_svg_surface_paint (void *abstract_surface, * and an optimiszation in meta surface. */ if (surface->clip_level == 0 && (op == CAIRO_OPERATOR_CLEAR || - op == CAIRO_OPERATOR_SOURCE)) { - _cairo_output_stream_destroy (surface->xml_node); + op == CAIRO_OPERATOR_SOURCE)) + { + status = _cairo_output_stream_destroy (surface->xml_node); + if (status) + return status; + surface->xml_node = _cairo_memory_stream_create (); if (op == CAIRO_OPERATOR_CLEAR) { @@ -1740,6 +1793,7 @@ _cairo_svg_surface_mask (void *abstract_surface, cairo_pattern_t *source, cairo_pattern_t *mask) { + cairo_status_t status; cairo_svg_surface_t *surface = abstract_surface; cairo_svg_document_t *document = surface->document; cairo_output_stream_t *mask_stream; @@ -1765,7 +1819,10 @@ _cairo_svg_surface_mask (void *abstract_surface, " </g>\n" "</mask>\n"); _cairo_memory_stream_copy (mask_stream, document->xml_node_defs); - _cairo_output_stream_destroy (mask_stream); + + status = _cairo_output_stream_destroy (mask_stream); + if (status) + return status; snprintf (buffer, sizeof buffer, "mask=\"url(#mask%d);\"", document->mask_id); @@ -2093,7 +2150,7 @@ _cairo_svg_document_destroy (cairo_svg_document_t *document) static cairo_status_t _cairo_svg_document_finish (cairo_svg_document_t *document) { - cairo_status_t status; + cairo_status_t status, status2; cairo_output_stream_t *output = document->output_stream; cairo_meta_snapshot_t *snapshot; cairo_svg_surface_t *surface; @@ -2113,7 +2170,10 @@ _cairo_svg_document_finish (cairo_svg_document_t *document) document->width, document->height, _cairo_svg_internal_version_strings [document->svg_version]); - _cairo_svg_document_emit_font_subsets (document); + status = _cairo_svg_document_emit_font_subsets (document); + if (status) + return status; + if (_cairo_memory_stream_length (document->xml_node_glyphs) > 0 || _cairo_memory_stream_length (document->xml_node_defs) > 0) { _cairo_output_stream_printf (output, "<defs>\n"); @@ -2158,10 +2218,15 @@ _cairo_svg_document_finish (cairo_svg_document_t *document) _cairo_output_stream_printf (output, "</svg>\n"); - _cairo_output_stream_destroy (document->xml_node_glyphs); - _cairo_output_stream_destroy (document->xml_node_defs); + status = _cairo_output_stream_destroy (document->xml_node_glyphs); + + status2 = _cairo_output_stream_destroy (document->xml_node_defs); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; - status = _cairo_output_stream_destroy (output); + status2 = _cairo_output_stream_destroy (output); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; for (i = 0; i < document->meta_snapshots.num_elements; i++) { snapshot = _cairo_array_index (&document->meta_snapshots, i); diff --git a/src/cairo-traps.c b/src/cairo-traps.c index 2fa4f66a1..f2b5ccbf2 100644 --- a/src/cairo-traps.c +++ b/src/cairo-traps.c @@ -43,7 +43,7 @@ static cairo_status_t _cairo_traps_grow (cairo_traps_t *traps); -static cairo_status_t +static void _cairo_traps_add_trap (cairo_traps_t *traps, cairo_fixed_t top, cairo_fixed_t bottom, cairo_line_t *left, cairo_line_t *right); @@ -87,45 +87,51 @@ cairo_status_t _cairo_traps_init_box (cairo_traps_t *traps, cairo_box_t *box) { - _cairo_traps_init (traps); + _cairo_traps_init (traps); - traps->status = _cairo_traps_grow (traps); - if (traps->status) - return traps->status; + traps->status = _cairo_traps_grow (traps); + if (traps->status) + return traps->status; - traps->num_traps = 1; + traps->num_traps = 1; - traps->traps[0].top = box->p1.y; - traps->traps[0].bottom = box->p2.y; - traps->traps[0].left.p1 = box->p1; - traps->traps[0].left.p2.x = box->p1.x; - traps->traps[0].left.p2.y = box->p2.y; - traps->traps[0].right.p1.x = box->p2.x; - traps->traps[0].right.p1.y = box->p1.y; - traps->traps[0].right.p2 = box->p2; + traps->traps[0].top = box->p1.y; + traps->traps[0].bottom = box->p2.y; + traps->traps[0].left.p1 = box->p1; + traps->traps[0].left.p2.x = box->p1.x; + traps->traps[0].left.p2.y = box->p2.y; + traps->traps[0].right.p1.x = box->p2.x; + traps->traps[0].right.p1.y = box->p1.y; + traps->traps[0].right.p2 = box->p2; - traps->extents = *box; + traps->extents = *box; - return traps->status; + return traps->status; } -static cairo_status_t +cairo_status_t +_cairo_traps_status (cairo_traps_t *traps) +{ + return traps->status; +} + +static void _cairo_traps_add_trap (cairo_traps_t *traps, cairo_fixed_t top, cairo_fixed_t bottom, cairo_line_t *left, cairo_line_t *right) { cairo_trapezoid_t *trap; if (traps->status) - return traps->status; + return; if (top == bottom) { - return CAIRO_STATUS_SUCCESS; + return; } if (traps->num_traps >= traps->traps_size) { traps->status = _cairo_traps_grow (traps); if (traps->status) - return traps->status; + return; } trap = &traps->traps[traps->num_traps]; @@ -157,11 +163,9 @@ _cairo_traps_add_trap (cairo_traps_t *traps, cairo_fixed_t top, cairo_fixed_t bo traps->extents.p2.x = right->p2.x; traps->num_traps++; - - return traps->status; } -cairo_status_t +void _cairo_traps_add_trap_from_points (cairo_traps_t *traps, cairo_fixed_t top, cairo_fixed_t bottom, cairo_point_t left_p1, cairo_point_t left_p2, cairo_point_t right_p1, cairo_point_t right_p2) @@ -170,7 +174,7 @@ _cairo_traps_add_trap_from_points (cairo_traps_t *traps, cairo_fixed_t top, cair cairo_line_t right; if (traps->status) - return traps->status; + return; left.p1 = left_p1; left.p2 = left_p2; @@ -178,7 +182,7 @@ _cairo_traps_add_trap_from_points (cairo_traps_t *traps, cairo_fixed_t top, cair right.p1 = right_p1; right.p2 = right_p2; - return _cairo_traps_add_trap (traps, top, bottom, &left, &right); + _cairo_traps_add_trap (traps, top, bottom, &left, &right); } /* make room for at least one more trap */ @@ -187,7 +191,7 @@ _cairo_traps_grow (cairo_traps_t *traps) { cairo_trapezoid_t *new_traps; int old_size = traps->traps_size; - int embedded_size = ARRAY_LEN (traps->traps_embedded); + int embedded_size = ARRAY_LENGTH (traps->traps_embedded); int new_size = 2 * MAX (old_size, 16); /* we have a local buffer at traps->traps_embedded. try to fulfill the request diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c index 262912ecf..e8137a755 100644 --- a/src/cairo-truetype-subset.c +++ b/src/cairo-truetype-subset.c @@ -320,16 +320,24 @@ 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) { + cairo_status_t status; + if (boundary - font->last_offset > SFNT_STRING_MAX_LENGTH) { - _cairo_array_append(&font->string_offsets, &font->last_boundary); + 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,12 +495,21 @@ 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) { + font->status = status; + break; + } + font->glyphs[i].location = next - start_offset; status = cairo_truetype_font_allocate_write_buffer (font, size, &buffer); - if (status) + if (status) { + font->status = status; break; + } + if (size != 0) { font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, TT_TAG_glyf, begin, buffer, &size); @@ -703,7 +720,7 @@ cairo_truetype_font_write_offset_table (cairo_truetype_font_t *font) unsigned short search_range, entry_selector, range_shift; int num_tables; - num_tables = ARRAY_LEN (truetype_tables); + num_tables = ARRAY_LENGTH (truetype_tables); search_range = 1; entry_selector = 0; while (search_range * 2 <= num_tables) { @@ -722,7 +739,7 @@ cairo_truetype_font_write_offset_table (cairo_truetype_font_t *font) /* Allocate space for the table directory. Each directory entry * will be filled in by cairo_truetype_font_update_entry() after * the table is written. */ - table_buffer_length = ARRAY_LEN (truetype_tables) * 16; + table_buffer_length = ARRAY_LENGTH (truetype_tables) * 16; status = cairo_truetype_font_allocate_write_buffer (font, table_buffer_length, &table_buffer); if (status) @@ -774,6 +791,7 @@ cairo_truetype_font_generate (cairo_truetype_font_t *font, const unsigned long **string_offsets, unsigned long *num_strings) { + cairo_status_t status; unsigned long start, end, next; uint32_t checksum, *checksum_location; unsigned int i; @@ -785,7 +803,7 @@ cairo_truetype_font_generate (cairo_truetype_font_t *font, end = start; end = 0; - for (i = 0; i < ARRAY_LEN (truetype_tables); i++) { + for (i = 0; i < ARRAY_LENGTH (truetype_tables); i++) { if (truetype_tables[i].write (font, truetype_tables[i].tag)) goto fail; @@ -793,7 +811,12 @@ 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); + status = cairo_truetype_font_check_boundary (font, next); + if (status) { + font->status = status; + goto fail; + } + start = next; } diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c index a183b28b4..a8f88df13 100644 --- a/src/cairo-type1-fallback.c +++ b/src/cairo-type1-fallback.c @@ -464,18 +464,21 @@ fail: return status; } -static void +static cairo_status_t cairo_type1_font_write_header (cairo_type1_font_t *font, const char *name) { cairo_matrix_t matrix; + cairo_status_t status; unsigned int i; const char spaces[50] = " "; 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; @@ -597,10 +603,10 @@ cairo_type1_font_write_private_dict (cairo_type1_font_t *font, "dup /FontName get exch definefont pop\n" "mark currentfile closefile\n"); - 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 +640,10 @@ 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 +681,18 @@ cairo_type1_font_generate (cairo_type1_font_t *font, const char *name) return CAIRO_STATUS_SUCCESS; } -static void +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,14 +758,14 @@ _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); fail3: free (type1_subset->widths); fail2: free (type1_subset->base_font); fail1: + /* status is already set, ignore further errors */ cairo_type1_font_destroy (font); return status; diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c index 82e3bfcf8..e1f263b67 100644 --- a/src/cairo-win32-font.c +++ b/src/cairo-win32-font.c @@ -283,11 +283,13 @@ _win32_scaled_font_create (LOGFONTW *logfont, cairo_matrix_multiply (&scale, font_matrix, ctm); _compute_transform (f, &scale); - _cairo_scaled_font_init (&f->base, font_face, - font_matrix, ctm, options, - &cairo_win32_scaled_font_backend); + status = _cairo_scaled_font_init (&f->base, font_face, + font_matrix, ctm, options, + &cairo_win32_scaled_font_backend); + + if (status == CAIRO_STATUS_SUCCESS) + status = _cairo_win32_scaled_font_set_metrics (f); - status = _cairo_win32_scaled_font_set_metrics (f); if (status) { cairo_scaled_font_destroy (&f->base); return NULL; diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index 7f1392dea..bfee1c7c5 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); @@ -876,6 +889,7 @@ _cairo_xlib_surface_clone_similar (void *abstract_surface, { cairo_xlib_surface_t *surface = abstract_surface; cairo_xlib_surface_t *clone; + cairo_status_t status; if (src->backend == surface->base.backend ) { cairo_xlib_surface_t *xlib_src = (cairo_xlib_surface_t *)src; @@ -897,8 +911,12 @@ _cairo_xlib_surface_clone_similar (void *abstract_surface, if (clone->base.status) return CAIRO_STATUS_NO_MEMORY; - _draw_image_surface (clone, image_src, src_x, src_y, - width, height, src_x, src_y); + status = _draw_image_surface (clone, image_src, src_x, src_y, + width, height, src_x, src_y); + if (status) { + cairo_surface_destroy (&clone->base); + return status; + } *clone_out = &clone->base; @@ -1029,15 +1047,17 @@ _cairo_xlib_surface_set_attributes (cairo_xlib_surface_t *surface, switch (attributes->extend) { case CAIRO_EXTEND_NONE: - _cairo_xlib_surface_set_repeat (surface, 0); + status = _cairo_xlib_surface_set_repeat (surface, 0); break; case CAIRO_EXTEND_REPEAT: - _cairo_xlib_surface_set_repeat (surface, 1); + status = _cairo_xlib_surface_set_repeat (surface, 1); break; case CAIRO_EXTEND_REFLECT: case CAIRO_EXTEND_PAD: - return CAIRO_INT_STATUS_UNSUPPORTED; + status = CAIRO_INT_STATUS_UNSUPPORTED; } + if (status) + return status; status = _cairo_xlib_surface_set_filter (surface, attributes->filter); if (status) @@ -1204,7 +1224,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 && @@ -1297,6 +1322,7 @@ _cairo_xlib_surface_composite (cairo_operator_t op, cairo_int_status_t status; composite_operation_t operation; int itx, ity; + cairo_bool_t is_integer_translation; if (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE (dst)) return CAIRO_INT_STATUS_UNSUPPORTED; @@ -1364,7 +1390,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,8 +1412,13 @@ _cairo_xlib_surface_composite (cairo_operator_t op, * _recategorize_composite_operation. */ - _cairo_xlib_surface_ensure_gc (dst); - _cairo_matrix_is_integer_translation (&src_attr.matrix, &itx, &ity); + status = _cairo_xlib_surface_ensure_gc (dst); + if (status) + goto BAIL; + is_integer_translation = _cairo_matrix_is_integer_translation (&src_attr.matrix, + &itx, &ity); + /* This is a pre-condition for DO_XTILE. */ + assert (is_integer_translation); XSetTSOrigin (dst->dpy, dst->gc, - (itx + src_attr.x_offset), - (ity + src_attr.y_offset)); @@ -2296,14 +2329,17 @@ _cairo_xlib_surface_font_init (Display *dpy, { cairo_xlib_surface_font_private_t *font_private; + font_private = malloc (sizeof (cairo_xlib_surface_font_private_t)); + if (!font_private) + return CAIRO_STATUS_NO_MEMORY; + if (!_cairo_xlib_add_close_display_hook (dpy, _cairo_xlib_surface_remove_scaled_font, - scaled_font, scaled_font)) + scaled_font, scaled_font)) { + free (font_private); return CAIRO_STATUS_NO_MEMORY; + } - font_private = malloc (sizeof (cairo_xlib_surface_font_private_t)); - if (!font_private) - return CAIRO_STATUS_NO_MEMORY; font_private->dpy = dpy; font_private->format = format; @@ -2793,7 +2829,11 @@ _cairo_xlib_surface_emit_glyphs (cairo_xlib_surface_t *dst, /* Send unsent glyphs to the server */ if (scaled_glyph->surface_private == NULL) { - _cairo_xlib_surface_add_glyph (dst->dpy, scaled_font, scaled_glyph); + status = _cairo_xlib_surface_add_glyph (dst->dpy, + scaled_font, + scaled_glyph); + if (status) + return status; scaled_glyph->surface_private = (void *) 1; } @@ -2898,6 +2938,8 @@ _cairo_xlib_surface_show_glyphs (void *abstract_dst, 0, 0, 1, 1, (cairo_surface_t **) &src, &attributes); + if (status) + goto BAIL0; } else { cairo_rectangle_int16_t glyph_extents; @@ -2906,38 +2948,42 @@ _cairo_xlib_surface_show_glyphs (void *abstract_dst, num_glyphs, &glyph_extents); if (status) - goto BAIL; + goto BAIL0; status = _cairo_pattern_acquire_surface (src_pattern, &dst->base, glyph_extents.x, glyph_extents.y, glyph_extents.width, glyph_extents.height, (cairo_surface_t **) &src, &attributes); + if (status) + goto BAIL0; } - if (status) - goto BAIL; - operation = _recategorize_composite_operation (dst, op, src, &attributes, TRUE); if (operation == DO_UNSUPPORTED) { status = CAIRO_INT_STATUS_UNSUPPORTED; - goto BAIL; + goto BAIL1; } status = _cairo_xlib_surface_set_attributes (src, &attributes); if (status) - goto BAIL; + goto BAIL1; - _cairo_xlib_surface_emit_glyphs (dst, (cairo_xlib_glyph_t *) glyphs, num_glyphs, - scaled_font, op, src, &attributes); - - BAIL: - _cairo_scaled_font_thaw_cache (scaled_font); + status = _cairo_xlib_surface_emit_glyphs (dst, + (cairo_xlib_glyph_t *) glyphs, + num_glyphs, + scaled_font, + op, + src, + &attributes); + BAIL1: if (src) _cairo_pattern_release_surface (src_pattern, &src->base, &attributes); if (src_pattern == &solid_pattern.base) _cairo_pattern_fini (&solid_pattern.base); + BAIL0: + _cairo_scaled_font_thaw_cache (scaled_font); return status; } diff --git a/src/cairo.c b/src/cairo.c index bf61596c1..abcdaff1a 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,14 +202,18 @@ 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 status with user error */ + status = CAIRO_STATUS_NULL_POINTER; } + if (status) + _cairo_set_error (cr, status); + return cr; } slim_hidden_def (cairo_create); @@ -483,9 +488,11 @@ cairo_push_group_with_content (cairo_t *cr, cairo_content_t content) parent_surface = _cairo_gstate_get_target (cr->gstate); /* Get the extents that we'll use in creating our new group surface */ - _cairo_surface_get_extents (parent_surface, &extents); + status = _cairo_surface_get_extents (parent_surface, &extents); + if (status) + goto bail; status = _cairo_clip_intersect_to_rectangle (_cairo_gstate_get_clip (cr->gstate), &extents); - if (status != CAIRO_STATUS_SUCCESS) + if (status) goto bail; group_surface = cairo_surface_create_similar (_cairo_gstate_get_target (cr->gstate), @@ -510,7 +517,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); @@ -563,7 +570,7 @@ cairo_pop_group (cairo_t *cr) /* We need to save group_surface before we restore; we don't need * to reference parent_target and original_target, since the * gstate will still hold refs to them once we restore. */ - cairo_surface_reference (group_surface); + group_surface = cairo_surface_reference (group_surface); cairo_restore (cr); @@ -572,7 +579,7 @@ cairo_pop_group (cairo_t *cr) group_pattern = cairo_pattern_create_for_surface (group_surface); if (!group_pattern) { - cr->status = CAIRO_STATUS_NO_MEMORY; + _cairo_set_error (cr, CAIRO_STATUS_NO_MEMORY); goto done; } @@ -639,12 +646,14 @@ slim_hidden_def(cairo_pop_group_to_source); void cairo_set_operator (cairo_t *cr, cairo_operator_t op) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_set_operator (cr->gstate, op); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_operator (cr->gstate, op); + if (status) + _cairo_set_error (cr, status); } slim_hidden_def (cairo_set_operator); @@ -783,6 +792,8 @@ slim_hidden_def (cairo_set_source_surface); void cairo_set_source (cairo_t *cr, cairo_pattern_t *source) { + cairo_status_t status; + if (cr->status) return; @@ -796,9 +807,9 @@ cairo_set_source (cairo_t *cr, cairo_pattern_t *source) return; } - cr->status = _cairo_gstate_set_source (cr->gstate, source); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_source (cr->gstate, source); + if (status) + _cairo_set_error (cr, status); } slim_hidden_def (cairo_set_source); @@ -837,14 +848,16 @@ cairo_get_source (cairo_t *cr) void cairo_set_tolerance (cairo_t *cr, double tolerance) { + cairo_status_t status; + if (cr->status) return; _cairo_restrict_value (&tolerance, CAIRO_TOLERANCE_MINIMUM, tolerance); - cr->status = _cairo_gstate_set_tolerance (cr->gstate, tolerance); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_tolerance (cr->gstate, tolerance); + if (status) + _cairo_set_error (cr, status); } /** @@ -863,12 +876,14 @@ cairo_set_tolerance (cairo_t *cr, double tolerance) void cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_set_antialias (cr->gstate, antialias); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_antialias (cr->gstate, antialias); + if (status) + _cairo_set_error (cr, status); } /** @@ -885,12 +900,14 @@ cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias) void cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_set_fill_rule (cr->gstate, fill_rule); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_fill_rule (cr->gstate, fill_rule); + if (status) + _cairo_set_error (cr, status); } /** @@ -922,14 +939,16 @@ cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule) void cairo_set_line_width (cairo_t *cr, double width) { + cairo_status_t status; + if (cr->status) return; _cairo_restrict_value (&width, 0.0, width); - cr->status = _cairo_gstate_set_line_width (cr->gstate, width); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_line_width (cr->gstate, width); + if (status) + _cairo_set_error (cr, status); } /** @@ -949,12 +968,14 @@ cairo_set_line_width (cairo_t *cr, double width) void cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_set_line_cap (cr->gstate, line_cap); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_line_cap (cr->gstate, line_cap); + if (status) + _cairo_set_error (cr, status); } /** @@ -974,12 +995,14 @@ cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap) void cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_set_line_join (cr->gstate, line_join); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_line_join (cr->gstate, line_join); + if (status) + _cairo_set_error (cr, status); } /** @@ -1020,13 +1043,15 @@ cairo_set_dash (cairo_t *cr, int num_dashes, double offset) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_set_dash (cr->gstate, - dashes, num_dashes, offset); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_dash (cr->gstate, + dashes, num_dashes, offset); + if (status) + _cairo_set_error (cr, status); } /** @@ -1094,12 +1119,14 @@ cairo_get_dash (cairo_t *cr, void cairo_set_miter_limit (cairo_t *cr, double limit) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_set_miter_limit (cr->gstate, limit); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_miter_limit (cr->gstate, limit); + if (status) + _cairo_set_error (cr, status); } /** @@ -1117,12 +1144,14 @@ cairo_set_miter_limit (cairo_t *cr, double limit) void cairo_translate (cairo_t *cr, double tx, double ty) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_translate (cr->gstate, tx, ty); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_translate (cr->gstate, tx, ty); + if (status) + _cairo_set_error (cr, status); } /** @@ -1139,12 +1168,14 @@ cairo_translate (cairo_t *cr, double tx, double ty) void cairo_scale (cairo_t *cr, double sx, double sy) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_scale (cr->gstate, sx, sy); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_scale (cr->gstate, sx, sy); + if (status) + _cairo_set_error (cr, status); } slim_hidden_def (cairo_scale); @@ -1163,12 +1194,14 @@ slim_hidden_def (cairo_scale); void cairo_rotate (cairo_t *cr, double angle) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_rotate (cr->gstate, angle); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_rotate (cr->gstate, angle); + if (status) + _cairo_set_error (cr, status); } /** @@ -1184,12 +1217,14 @@ void cairo_transform (cairo_t *cr, const cairo_matrix_t *matrix) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_transform (cr->gstate, matrix); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_transform (cr->gstate, matrix); + if (status) + _cairo_set_error (cr, status); } /** @@ -1204,12 +1239,14 @@ void cairo_set_matrix (cairo_t *cr, const cairo_matrix_t *matrix) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_set_matrix (cr->gstate, matrix); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_matrix (cr->gstate, matrix); + if (status) + _cairo_set_error (cr, status); } /** @@ -1227,9 +1264,7 @@ cairo_identity_matrix (cairo_t *cr) if (cr->status) return; - cr->status = _cairo_gstate_identity_matrix (cr->gstate); - if (cr->status) - _cairo_set_error (cr, cr->status); + _cairo_gstate_identity_matrix (cr->gstate); } /** @@ -1248,9 +1283,7 @@ cairo_user_to_device (cairo_t *cr, double *x, double *y) if (cr->status) return; - cr->status = _cairo_gstate_user_to_device (cr->gstate, x, y); - if (cr->status) - _cairo_set_error (cr, cr->status); + _cairo_gstate_user_to_device (cr->gstate, x, y); } /** @@ -1270,9 +1303,7 @@ cairo_user_to_device_distance (cairo_t *cr, double *dx, double *dy) if (cr->status) return; - cr->status = _cairo_gstate_user_to_device_distance (cr->gstate, dx, dy); - if (cr->status) - _cairo_set_error (cr, cr->status); + _cairo_gstate_user_to_device_distance (cr->gstate, dx, dy); } /** @@ -1291,9 +1322,7 @@ cairo_device_to_user (cairo_t *cr, double *x, double *y) if (cr->status) return; - cr->status = _cairo_gstate_device_to_user (cr->gstate, x, y); - if (cr->status) - _cairo_set_error (cr, cr->status); + _cairo_gstate_device_to_user (cr->gstate, x, y); } /** @@ -1313,9 +1342,7 @@ cairo_device_to_user_distance (cairo_t *cr, double *dx, double *dy) if (cr->status) return; - cr->status = _cairo_gstate_device_to_user_distance (cr->gstate, dx, dy); - if (cr->status) - _cairo_set_error (cr, cr->status); + _cairo_gstate_device_to_user_distance (cr->gstate, dx, dy); } /** @@ -1347,6 +1374,7 @@ slim_hidden_def(cairo_new_path); void cairo_move_to (cairo_t *cr, double x, double y) { + cairo_status_t status; cairo_fixed_t x_fixed, y_fixed; if (cr->status) @@ -1356,9 +1384,9 @@ cairo_move_to (cairo_t *cr, double x, double y) x_fixed = _cairo_fixed_from_double (x); y_fixed = _cairo_fixed_from_double (y); - cr->status = _cairo_path_fixed_move_to (cr->path, x_fixed, y_fixed); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_path_fixed_move_to (cr->path, x_fixed, y_fixed); + if (status) + _cairo_set_error (cr, status); } slim_hidden_def(cairo_move_to); @@ -1405,6 +1433,7 @@ cairo_new_sub_path (cairo_t *cr) void cairo_line_to (cairo_t *cr, double x, double y) { + cairo_status_t status; cairo_fixed_t x_fixed, y_fixed; if (cr->status) @@ -1414,9 +1443,9 @@ cairo_line_to (cairo_t *cr, double x, double y) x_fixed = _cairo_fixed_from_double (x); y_fixed = _cairo_fixed_from_double (y); - cr->status = _cairo_path_fixed_line_to (cr->path, x_fixed, y_fixed); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_path_fixed_line_to (cr->path, x_fixed, y_fixed); + if (status) + _cairo_set_error (cr, status); } slim_hidden_def (cairo_line_to); @@ -1445,6 +1474,7 @@ cairo_curve_to (cairo_t *cr, double x2, double y2, double x3, double y3) { + cairo_status_t status; cairo_fixed_t x1_fixed, y1_fixed; cairo_fixed_t x2_fixed, y2_fixed; cairo_fixed_t x3_fixed, y3_fixed; @@ -1465,12 +1495,12 @@ cairo_curve_to (cairo_t *cr, x3_fixed = _cairo_fixed_from_double (x3); y3_fixed = _cairo_fixed_from_double (y3); - cr->status = _cairo_path_fixed_curve_to (cr->path, - x1_fixed, y1_fixed, - x2_fixed, y2_fixed, - x3_fixed, y3_fixed); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_path_fixed_curve_to (cr->path, + x1_fixed, y1_fixed, + x2_fixed, y2_fixed, + x3_fixed, y3_fixed); + if (status) + _cairo_set_error (cr, status); } slim_hidden_def (cairo_curve_to); @@ -1593,13 +1623,17 @@ cairo_arc_to (cairo_t *cr, double x2, double y2, double radius) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_arc_to (cr->gstate, - x1, y1, - x2, y2, - radius); + status = _cairo_gstate_arc_to (cr->gstate, + x1, y1, + x2, y2, + radius); + if (status) + _cairo_set_error (cr, status); } */ @@ -1623,17 +1657,19 @@ 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); - 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); } /** @@ -1658,17 +1694,19 @@ 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); - 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); @@ -1707,6 +1745,7 @@ 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; @@ -1724,12 +1763,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) - _cairo_set_error (cr, cr->status); + status = _cairo_path_fixed_rel_curve_to (cr->path, + dx1_fixed, dy1_fixed, + dx2_fixed, dy2_fixed, + dx3_fixed, dy3_fixed); + if (status) + _cairo_set_error (cr, status); } /** @@ -1771,12 +1810,14 @@ cairo_rectangle (cairo_t *cr, void cairo_stroke_to_path (cairo_t *cr) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_stroke_path (cr->gstate); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_stroke_path (cr->gstate); + if (status) + _cairo_set_error (cr, status); } */ @@ -1809,12 +1850,14 @@ cairo_stroke_to_path (cairo_t *cr) void cairo_close_path (cairo_t *cr) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_path_fixed_close_path (cr->path); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_path_fixed_close_path (cr->path); + if (status) + _cairo_set_error (cr, status); } slim_hidden_def(cairo_close_path); @@ -1828,12 +1871,14 @@ slim_hidden_def(cairo_close_path); void cairo_paint (cairo_t *cr) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_paint (cr->gstate); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_paint (cr->gstate); + if (status) + _cairo_set_error (cr, status); } slim_hidden_def (cairo_paint); @@ -1851,6 +1896,7 @@ void cairo_paint_with_alpha (cairo_t *cr, double alpha) { + cairo_status_t status; cairo_color_t color; cairo_pattern_union_t pattern; @@ -1869,9 +1915,9 @@ cairo_paint_with_alpha (cairo_t *cr, _cairo_color_init_rgba (&color, 1., 1., 1., alpha); _cairo_pattern_init_solid (&pattern.solid, &color); - cr->status = _cairo_gstate_mask (cr->gstate, &pattern.base); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_mask (cr->gstate, &pattern.base); + if (status) + _cairo_set_error (cr, status); _cairo_pattern_fini (&pattern.base); } @@ -1890,6 +1936,8 @@ void cairo_mask (cairo_t *cr, cairo_pattern_t *pattern) { + cairo_status_t status; + if (cr->status) return; @@ -1903,9 +1951,9 @@ cairo_mask (cairo_t *cr, return; } - cr->status = _cairo_gstate_mask (cr->gstate, pattern); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_mask (cr->gstate, pattern); + if (status) + _cairo_set_error (cr, status); } slim_hidden_def (cairo_mask); @@ -1999,12 +2047,14 @@ cairo_stroke (cairo_t *cr) void cairo_stroke_preserve (cairo_t *cr) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_stroke (cr->gstate, cr->path); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_stroke (cr->gstate, cr->path); + if (status) + _cairo_set_error (cr, status); } slim_hidden_def(cairo_stroke_preserve); @@ -2040,12 +2090,14 @@ cairo_fill (cairo_t *cr) void cairo_fill_preserve (cairo_t *cr) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_fill (cr->gstate, cr->path); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_fill (cr->gstate, cr->path); + if (status) + _cairo_set_error (cr, status); } slim_hidden_def(cairo_fill_preserve); @@ -2061,12 +2113,14 @@ slim_hidden_def(cairo_fill_preserve); void cairo_copy_page (cairo_t *cr) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_copy_page (cr->gstate); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_copy_page (cr->gstate); + if (status) + _cairo_set_error (cr, status); } /** @@ -2079,12 +2133,14 @@ cairo_copy_page (cairo_t *cr) void cairo_show_page (cairo_t *cr) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_show_page (cr->gstate); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_show_page (cr->gstate); + if (status) + _cairo_set_error (cr, status); } /** @@ -2107,16 +2163,17 @@ cairo_show_page (cairo_t *cr) cairo_bool_t cairo_in_stroke (cairo_t *cr, double x, double y) { - cairo_bool_t inside; + cairo_status_t status; + cairo_bool_t inside = FALSE; if (cr->status) return 0; - cr->status = _cairo_gstate_in_stroke (cr->gstate, - cr->path, - x, y, &inside); - if (cr->status) - return 0; + status = _cairo_gstate_in_stroke (cr->gstate, + cr->path, + x, y, &inside); + if (status) + _cairo_set_error (cr, status); return inside; } @@ -2139,18 +2196,17 @@ cairo_in_stroke (cairo_t *cr, double x, double y) cairo_bool_t cairo_in_fill (cairo_t *cr, double x, double y) { - cairo_bool_t inside; + cairo_status_t status; + cairo_bool_t inside = FALSE; if (cr->status) return 0; - cr->status = _cairo_gstate_in_fill (cr->gstate, - cr->path, - x, y, &inside); - if (cr->status) { - _cairo_set_error (cr, cr->status); - return 0; - } + status = _cairo_gstate_in_fill (cr->gstate, + cr->path, + x, y, &inside); + if (status) + _cairo_set_error (cr, status); return inside; } @@ -2177,14 +2233,16 @@ void cairo_stroke_extents (cairo_t *cr, double *x1, double *y1, double *x2, double *y2) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_stroke_extents (cr->gstate, - cr->path, - x1, y1, x2, y2); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_stroke_extents (cr->gstate, + cr->path, + x1, y1, x2, y2); + if (status) + _cairo_set_error (cr, status); } /** @@ -2207,14 +2265,16 @@ void cairo_fill_extents (cairo_t *cr, double *x1, double *y1, double *x2, double *y2) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_fill_extents (cr->gstate, - cr->path, - x1, y1, x2, y2); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_fill_extents (cr->gstate, + cr->path, + x1, y1, x2, y2); + if (status) + _cairo_set_error (cr, status); } /** @@ -2272,12 +2332,14 @@ cairo_clip (cairo_t *cr) void cairo_clip_preserve (cairo_t *cr) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_clip (cr->gstate, cr->path); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_clip (cr->gstate, cr->path); + if (status) + _cairo_set_error (cr, status); } slim_hidden_def(cairo_clip_preserve); @@ -2300,12 +2362,14 @@ slim_hidden_def(cairo_clip_preserve); void cairo_reset_clip (cairo_t *cr) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_reset_clip (cr->gstate); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_reset_clip (cr->gstate); + if (status) + _cairo_set_error (cr, status); } /** @@ -2326,12 +2390,14 @@ cairo_clip_extents (cairo_t *cr, double *x1, double *y1, double *x2, double *y2) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_clip_extents (cr->gstate, x1, y1, x2, y2); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_clip_extents (cr->gstate, x1, y1, x2, y2); + if (status) + _cairo_set_error (cr, status); } static cairo_rectangle_list_t * @@ -2397,12 +2463,14 @@ cairo_select_font_face (cairo_t *cr, cairo_font_slant_t slant, cairo_font_weight_t weight) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_select_font_face (cr->gstate, family, slant, weight); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_select_font_face (cr->gstate, family, slant, weight); + if (status) + _cairo_set_error (cr, status); } /** @@ -2417,12 +2485,14 @@ void cairo_font_extents (cairo_t *cr, cairo_font_extents_t *extents) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_get_font_extents (cr->gstate, extents); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_get_font_extents (cr->gstate, extents); + if (status) + _cairo_set_error (cr, status); } /** @@ -2438,12 +2508,14 @@ void cairo_set_font_face (cairo_t *cr, cairo_font_face_t *font_face) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_set_font_face (cr->gstate, font_face); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_font_face (cr->gstate, font_face); + if (status) + _cairo_set_error (cr, status); } /** @@ -2467,14 +2539,15 @@ cairo_set_font_face (cairo_t *cr, cairo_font_face_t * cairo_get_font_face (cairo_t *cr) { + cairo_status_t status; cairo_font_face_t *font_face; if (cr->status) return (cairo_font_face_t*) &_cairo_font_face_nil; - cr->status = _cairo_gstate_get_font_face (cr->gstate, &font_face); - if (cr->status) { - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_get_font_face (cr->gstate, &font_face); + if (status) { + _cairo_set_error (cr, status); return (cairo_font_face_t*) &_cairo_font_face_nil; } @@ -2495,12 +2568,14 @@ cairo_get_font_face (cairo_t *cr) void cairo_set_font_size (cairo_t *cr, double size) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_set_font_size (cr->gstate, size); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_font_size (cr->gstate, size); + if (status) + _cairo_set_error (cr, status); } /** @@ -2520,12 +2595,14 @@ void cairo_set_font_matrix (cairo_t *cr, const cairo_matrix_t *matrix) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_set_font_matrix (cr->gstate, matrix); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_font_matrix (cr->gstate, matrix); + if (status) + _cairo_set_error (cr, status); } /** @@ -2557,12 +2634,14 @@ void cairo_set_font_options (cairo_t *cr, const cairo_font_options_t *options) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_set_font_options (cr->gstate, options); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_set_font_options (cr->gstate, options); + if (status) + _cairo_set_error (cr, status); } /** @@ -2600,29 +2679,31 @@ void cairo_set_scaled_font (cairo_t *cr, const cairo_scaled_font_t *scaled_font) { + cairo_status_t status; + if (cr->status) return; - cr->status = scaled_font->status; - if (cr->status) + status = scaled_font->status; + if (status) goto BAIL; - cr->status = _cairo_gstate_set_font_face (cr->gstate, scaled_font->font_face); - if (cr->status) + status = _cairo_gstate_set_font_face (cr->gstate, scaled_font->font_face); + if (status) goto BAIL; - cr->status = _cairo_gstate_set_font_matrix (cr->gstate, &scaled_font->font_matrix); - if (cr->status) + status = _cairo_gstate_set_font_matrix (cr->gstate, &scaled_font->font_matrix); + if (status) goto BAIL; - cr->status = _cairo_gstate_set_font_options (cr->gstate, &scaled_font->options); - if (cr->status) + status = _cairo_gstate_set_font_options (cr->gstate, &scaled_font->options); + if (status) goto BAIL; return; BAIL: - _cairo_set_error (cr, cr->status); + _cairo_set_error (cr, status); } /** @@ -2648,14 +2729,15 @@ BAIL: cairo_scaled_font_t * cairo_get_scaled_font (cairo_t *cr) { + cairo_status_t status; cairo_scaled_font_t *scaled_font; if (cr->status) return (cairo_scaled_font_t *)&_cairo_scaled_font_nil; - cr->status = _cairo_gstate_get_scaled_font (cr->gstate, &scaled_font); - if (cr->status) { - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_get_scaled_font (cr->gstate, &scaled_font); + if (status) { + _cairo_set_error (cr, status); return (cairo_scaled_font_t *)&_cairo_scaled_font_nil; } @@ -2687,6 +2769,7 @@ cairo_text_extents (cairo_t *cr, const char *utf8, cairo_text_extents_t *extents) { + cairo_status_t status; cairo_glyph_t *glyphs = NULL; int num_glyphs; double x, y; @@ -2706,23 +2789,23 @@ cairo_text_extents (cairo_t *cr, cairo_get_current_point (cr, &x, &y); - cr->status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8, - x, y, - &glyphs, &num_glyphs); + status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8, + x, y, + &glyphs, &num_glyphs); - if (cr->status) { + if (status) { if (glyphs) free (glyphs); - _cairo_set_error (cr, cr->status); + _cairo_set_error (cr, status); return; } - cr->status = _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs, extents); + status = _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs, extents); if (glyphs) free (glyphs); - if (cr->status) - _cairo_set_error (cr, cr->status); + if (status) + _cairo_set_error (cr, status); } /** @@ -2749,13 +2832,15 @@ cairo_glyph_extents (cairo_t *cr, int num_glyphs, cairo_text_extents_t *extents) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs, - extents); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs, + extents); + if (status) + _cairo_set_error (cr, status); } /** @@ -2789,6 +2874,7 @@ void cairo_show_text (cairo_t *cr, const char *utf8) { cairo_text_extents_t extents; + cairo_status_t status; cairo_glyph_t *glyphs = NULL, *last_glyph; int num_glyphs; double x, y; @@ -2801,24 +2887,24 @@ cairo_show_text (cairo_t *cr, const char *utf8) cairo_get_current_point (cr, &x, &y); - cr->status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8, + status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8, x, y, &glyphs, &num_glyphs); - if (cr->status) + if (status) goto BAIL; if (num_glyphs == 0) return; - cr->status = _cairo_gstate_show_glyphs (cr->gstate, glyphs, num_glyphs); - if (cr->status) + status = _cairo_gstate_show_glyphs (cr->gstate, glyphs, num_glyphs); + if (status) goto BAIL; last_glyph = &glyphs[num_glyphs - 1]; - cr->status = _cairo_gstate_glyph_extents (cr->gstate, - last_glyph, 1, - &extents); - if (cr->status) + status = _cairo_gstate_glyph_extents (cr->gstate, + last_glyph, 1, + &extents); + if (status) goto BAIL; x = last_glyph->x + extents.x_advance; @@ -2829,8 +2915,8 @@ cairo_show_text (cairo_t *cr, const char *utf8) if (glyphs) free (glyphs); - if (cr->status) - _cairo_set_error (cr, cr->status); + if (status) + _cairo_set_error (cr, status); } /** @@ -2846,15 +2932,17 @@ cairo_show_text (cairo_t *cr, const char *utf8) void cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs) { + cairo_status_t status; + if (cr->status) return; if (num_glyphs == 0) return; - cr->status = _cairo_gstate_show_glyphs (cr->gstate, glyphs, num_glyphs); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_show_glyphs (cr->gstate, glyphs, num_glyphs); + if (status) + _cairo_set_error (cr, status); } /** @@ -2884,6 +2972,7 @@ cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs) void cairo_text_path (cairo_t *cr, const char *utf8) { + cairo_status_t status; cairo_text_extents_t extents; cairo_glyph_t *glyphs = NULL, *last_glyph; int num_glyphs; @@ -2894,29 +2983,29 @@ cairo_text_path (cairo_t *cr, const char *utf8) cairo_get_current_point (cr, &x, &y); - cr->status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8, - x, y, - &glyphs, &num_glyphs); + status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8, + x, y, + &glyphs, &num_glyphs); - if (cr->status) + if (status) goto BAIL; if (num_glyphs == 0) return; - cr->status = _cairo_gstate_glyph_path (cr->gstate, - glyphs, num_glyphs, - cr->path); + status = _cairo_gstate_glyph_path (cr->gstate, + glyphs, num_glyphs, + cr->path); - if (cr->status) + if (status) goto BAIL; last_glyph = &glyphs[num_glyphs - 1]; - cr->status = _cairo_gstate_glyph_extents (cr->gstate, - last_glyph, 1, - &extents); + status = _cairo_gstate_glyph_extents (cr->gstate, + last_glyph, 1, + &extents); - if (cr->status) + if (status) goto BAIL; x = last_glyph->x + extents.x_advance; @@ -2927,8 +3016,8 @@ cairo_text_path (cairo_t *cr, const char *utf8) if (glyphs) free (glyphs); - if (cr->status) - _cairo_set_error (cr, cr->status); + if (status) + _cairo_set_error (cr, status); } /** @@ -2944,14 +3033,16 @@ cairo_text_path (cairo_t *cr, const char *utf8) void cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs) { + cairo_status_t status; + if (cr->status) return; - cr->status = _cairo_gstate_glyph_path (cr->gstate, - glyphs, num_glyphs, - cr->path); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_gstate_glyph_path (cr->gstate, + glyphs, num_glyphs, + cr->path); + if (status) + _cairo_set_error (cr, status); } /** @@ -3278,6 +3369,8 @@ void cairo_append_path (cairo_t *cr, const cairo_path_t *path) { + cairo_status_t status; + if (cr->status) return; @@ -3300,9 +3393,9 @@ cairo_append_path (cairo_t *cr, return; } - cr->status = _cairo_path_append_to_context (path, cr); - if (cr->status) - _cairo_set_error (cr, cr->status); + status = _cairo_path_append_to_context (path, cr); + if (status) + _cairo_set_error (cr, status); } /** diff --git a/src/cairo.h b/src/cairo.h index a80efde21..5fc05e355 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -313,7 +313,7 @@ cairo_public void * cairo_get_user_data (cairo_t *cr, const cairo_user_data_key_t *key); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_set_user_data (cairo_t *cr, const cairo_user_data_key_t *key, void *user_data, @@ -972,7 +972,7 @@ cairo_font_options_copy (const cairo_font_options_t *original); cairo_public void cairo_font_options_destroy (cairo_font_options_t *options); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_font_options_status (cairo_font_options_t *options); cairo_public void @@ -1088,7 +1088,7 @@ cairo_font_face_destroy (cairo_font_face_t *font_face); cairo_public unsigned int cairo_font_face_get_reference_count (cairo_font_face_t *font_face); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_font_face_status (cairo_font_face_t *font_face); /** @@ -1141,7 +1141,7 @@ cairo_public void * cairo_font_face_get_user_data (cairo_font_face_t *font_face, const cairo_user_data_key_t *key); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_font_face_set_user_data (cairo_font_face_t *font_face, const cairo_user_data_key_t *key, void *user_data, @@ -1164,7 +1164,7 @@ cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font); cairo_public unsigned int cairo_scaled_font_get_reference_count (cairo_scaled_font_t *scaled_font); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_scaled_font_status (cairo_scaled_font_t *scaled_font); cairo_public cairo_font_type_t @@ -1174,7 +1174,7 @@ cairo_public void * cairo_scaled_font_get_user_data (cairo_scaled_font_t *scaled_font, const cairo_user_data_key_t *key); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_scaled_font_set_user_data (cairo_scaled_font_t *scaled_font, const cairo_user_data_key_t *key, void *user_data, @@ -1392,7 +1392,7 @@ cairo_path_destroy (cairo_path_t *path); /* Error status queries */ -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_status (cairo_t *cr); cairo_public const char * @@ -1418,7 +1418,7 @@ cairo_surface_destroy (cairo_surface_t *surface); cairo_public unsigned int cairo_surface_get_reference_count (cairo_surface_t *surface); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_surface_status (cairo_surface_t *surface); /** @@ -1482,11 +1482,11 @@ cairo_surface_get_content (cairo_surface_t *surface); #if CAIRO_HAS_PNG_FUNCTIONS -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_surface_write_to_png (cairo_surface_t *surface, const char *filename); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_surface_write_to_png_stream (cairo_surface_t *surface, cairo_write_func_t write_func, void *closure); @@ -1497,7 +1497,7 @@ cairo_public void * cairo_surface_get_user_data (cairo_surface_t *surface, const cairo_user_data_key_t *key); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_surface_set_user_data (cairo_surface_t *surface, const cairo_user_data_key_t *key, void *user_data, @@ -1642,14 +1642,14 @@ cairo_pattern_destroy (cairo_pattern_t *pattern); cairo_public unsigned int cairo_pattern_get_reference_count (cairo_pattern_t *pattern); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_pattern_status (cairo_pattern_t *pattern); cairo_public void * cairo_pattern_get_user_data (cairo_pattern_t *pattern, const cairo_user_data_key_t *key); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_pattern_set_user_data (cairo_pattern_t *pattern, const cairo_user_data_key_t *key, void *user_data, @@ -1758,32 +1758,32 @@ cairo_pattern_set_filter (cairo_pattern_t *pattern, cairo_filter_t filter); cairo_public cairo_filter_t cairo_pattern_get_filter (cairo_pattern_t *pattern); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_pattern_get_rgba (cairo_pattern_t *pattern, double *red, double *green, double *blue, double *alpha); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_pattern_get_surface (cairo_pattern_t *pattern, cairo_surface_t **surface); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_pattern_get_color_stop_rgba (cairo_pattern_t *pattern, int index, double *offset, double *red, double *green, double *blue, double *alpha); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_pattern_get_color_stop_count (cairo_pattern_t *pattern, int *count); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_pattern_get_linear_points (cairo_pattern_t *pattern, double *x0, double *y0, double *x1, double *y1); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_pattern_get_radial_circles (cairo_pattern_t *pattern, double *x0, double *y0, double *r0, double *x1, double *y1, double *r1); @@ -1820,7 +1820,7 @@ cairo_matrix_scale (cairo_matrix_t *matrix, double sx, double sy); cairo_public void cairo_matrix_rotate (cairo_matrix_t *matrix, double radians); -cairo_public cairo_status_t +cairo_public_warn cairo_status_t cairo_matrix_invert (cairo_matrix_t *matrix); cairo_public void diff --git a/src/cairoint.h b/src/cairoint.h index 77eda9060..628ee416a 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -73,13 +73,13 @@ CAIRO_BEGIN_DECLS #if __GNUC__ >= 3 && defined(__ELF__) && !defined(__sun) -# define slim_hidden_proto(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) -# define slim_hidden_def(name) slim_hidden_def1(name, slim_hidden_int_name(name)) +# define slim_hidden_proto(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private +# define slim_hidden_proto_no_warn(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private_no_warn +# define slim_hidden_def(name) slim_hidden_def1(name, slim_hidden_int_name(name)) # define slim_hidden_int_name(name) INT_##name # define slim_hidden_proto1(name, internal) \ extern __typeof (name) name \ - __asm__ (slim_hidden_asmname (internal)) \ - cairo_private + __asm__ (slim_hidden_asmname (internal)) # define slim_hidden_def1(name, internal) \ extern __typeof (name) EXT_##name __asm__(slim_hidden_asmname(name)) \ __attribute__((__alias__(slim_hidden_asmname(internal)))) @@ -89,8 +89,9 @@ CAIRO_BEGIN_DECLS # define slim_hidden_asmname(name) slim_hidden_asmname1(name) # define slim_hidden_asmname1(name) slim_hidden_ulp #name #else -# define slim_hidden_proto(name) int _cairo_dummy_prototype(void) -# define slim_hidden_def(name) int _cairo_dummy_prototype(void) +# define slim_hidden_proto(name) int _cairo_dummy_prototype(void) +# define slim_hidden_proto_no_warn(name) int _cairo_dummy_prototype(void) +# define slim_hidden_def(name) int _cairo_dummy_prototype(void) #endif #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) @@ -102,13 +103,18 @@ CAIRO_BEGIN_DECLS /* slim_internal.h */ #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun) -#define cairo_private __attribute__((__visibility__("hidden"))) +#define cairo_private __attribute__((__visibility__("hidden"),__warn_unused_result__)) +#define cairo_private_no_warn __attribute__((__visibility__("hidden"))) #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) -#define cairo_private __hidden +#define cairo_private __hidden CAIRO_WARN_UNUSED_RESULT +#define cairo_private_no_warn __hidden #else /* not gcc >= 3.3 and not Sun Studio >= 8 */ -#define cairo_private +#define cairo_private CAIRO_WARN_UNUSED_RESULT +#define cairo_private_no_warn #endif +#define cairo_warn CAIRO_WARN_UNUSED_RESULT + /* This macro allow us to deprecate a function by providing an alias for the old function name to the new function name. With this macro, binary compatibility is preserved. The macro only works on @@ -151,8 +157,8 @@ CAIRO_BEGIN_DECLS #define M_PI 3.14159265358979323846 #endif -#undef ARRAY_LEN -#define ARRAY_LEN(__array) ((int) (sizeof (__array) / sizeof (__array[0]))) +#undef ARRAY_LENGTH +#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0]))) /* Size in bytes of buffer to use off the stack per functions. * Mostly used by text functions. For larger allocations, they'll @@ -345,6 +351,8 @@ typedef struct _cairo_edge { } cairo_edge_t; typedef struct _cairo_polygon { + cairo_status_t status; + cairo_point_t first_point; cairo_point_t current_point; cairo_bool_t has_current_point; @@ -1253,7 +1261,7 @@ _cairo_gstate_restore (cairo_gstate_t **gstate); cairo_private cairo_bool_t _cairo_gstate_is_redirected (cairo_gstate_t *gstate); -cairo_private void +cairo_private cairo_status_t _cairo_gstate_redirect_target (cairo_gstate_t *gstate, cairo_surface_t *child); cairo_private cairo_surface_t * @@ -1342,19 +1350,19 @@ cairo_private cairo_status_t _cairo_gstate_set_matrix (cairo_gstate_t *gstate, const cairo_matrix_t *matrix); -cairo_private cairo_status_t +cairo_private void _cairo_gstate_identity_matrix (cairo_gstate_t *gstate); -cairo_private cairo_status_t +cairo_private void _cairo_gstate_user_to_device (cairo_gstate_t *gstate, double *x, double *y); -cairo_private cairo_status_t +cairo_private void _cairo_gstate_user_to_device_distance (cairo_gstate_t *gstate, double *dx, double *dy); -cairo_private cairo_status_t +cairo_private void _cairo_gstate_device_to_user (cairo_gstate_t *gstate, double *x, double *y); -cairo_private cairo_status_t +cairo_private void _cairo_gstate_device_to_user_distance (cairo_gstate_t *gstate, double *dx, double *dy); cairo_private void @@ -1587,7 +1595,7 @@ cairo_private void _cairo_unscaled_font_init (cairo_unscaled_font_t *font, const cairo_unscaled_font_backend_t *backend); -cairo_private cairo_unscaled_font_t * +cairo_private_no_warn cairo_unscaled_font_t * _cairo_unscaled_font_reference (cairo_unscaled_font_t *font); cairo_private void @@ -1944,10 +1952,10 @@ _cairo_surface_composite_trapezoids (cairo_operator_t op, cairo_trapezoid_t *traps, int ntraps); -cairo_private cairo_int_status_t +cairo_private cairo_status_t _cairo_surface_copy_page (cairo_surface_t *surface); -cairo_private cairo_int_status_t +cairo_private cairo_status_t _cairo_surface_show_page (cairo_surface_t *surface); cairo_private cairo_status_t @@ -2174,7 +2182,7 @@ _cairo_pen_init (cairo_pen_t *pen, double tolerance, cairo_matrix_t *ctm); -cairo_private cairo_status_t +cairo_private void _cairo_pen_init_empty (cairo_pen_t *pen); cairo_private cairo_status_t @@ -2217,15 +2225,18 @@ cairo_private void _cairo_polygon_fini (cairo_polygon_t *polygon); cairo_private cairo_status_t +_cairo_polygon_status (cairo_polygon_t *polygon); + +cairo_private void _cairo_polygon_add_edge (cairo_polygon_t *polygon, cairo_point_t *p1, cairo_point_t *p2); -cairo_private cairo_status_t +cairo_private void _cairo_polygon_move_to (cairo_polygon_t *polygon, cairo_point_t *point); -cairo_private cairo_status_t +cairo_private void _cairo_polygon_line_to (cairo_polygon_t *polygon, cairo_point_t *point); -cairo_private cairo_status_t +cairo_private void _cairo_polygon_close (cairo_polygon_t *polygon); /* cairo_spline.c */ @@ -2258,7 +2269,7 @@ _cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix, cairo_private void _cairo_matrix_compute_determinant (const cairo_matrix_t *matrix, double *det); -cairo_private cairo_status_t +cairo_private void _cairo_matrix_compute_scale_factors (const cairo_matrix_t *matrix, double *sx, double *sy, int x_major); @@ -2290,6 +2301,9 @@ _cairo_traps_init_box (cairo_traps_t *traps, cairo_private void _cairo_traps_fini (cairo_traps_t *traps); +cairo_private cairo_status_t +_cairo_traps_status (cairo_traps_t *traps); + cairo_private void _cairo_traps_translate (cairo_traps_t *traps, int x, int y); @@ -2304,7 +2318,7 @@ _cairo_traps_tessellate_polygon (cairo_traps_t *traps, cairo_polygon_t *poly, cairo_fill_rule_t fill_rule); -cairo_private cairo_status_t +cairo_private void _cairo_traps_add_trap_from_points (cairo_traps_t *traps, cairo_fixed_t top, cairo_fixed_t bottom, cairo_point_t left_p1, cairo_point_t left_p2, cairo_point_t right_p1, cairo_point_t right_p2); @@ -2450,9 +2464,6 @@ _cairo_utf8_to_utf16 (const unsigned char *str, cairo_private void _cairo_error (cairo_status_t status); -cairo_private int -_cairo_dtostr (char *buffer, size_t size, double d); - /* Avoid unnecessary PLT entries. */ slim_hidden_proto (cairo_clip_preserve); slim_hidden_proto (cairo_close_path); @@ -2461,7 +2472,7 @@ slim_hidden_proto (cairo_curve_to); slim_hidden_proto (cairo_destroy); slim_hidden_proto (cairo_fill_preserve); slim_hidden_proto (cairo_font_face_destroy); -slim_hidden_proto (cairo_font_face_reference); +slim_hidden_proto_no_warn (cairo_font_face_reference); slim_hidden_proto (cairo_font_options_create); slim_hidden_proto (cairo_font_options_destroy); slim_hidden_proto (cairo_font_options_equal); @@ -2500,7 +2511,7 @@ slim_hidden_proto (cairo_pattern_create_rgba); slim_hidden_proto (cairo_pattern_destroy); slim_hidden_proto (cairo_pattern_get_extend); slim_hidden_proto (cairo_pattern_get_type); -slim_hidden_proto (cairo_pattern_reference); +slim_hidden_proto_no_warn (cairo_pattern_reference); slim_hidden_proto (cairo_pattern_set_matrix); slim_hidden_proto (cairo_pattern_status); slim_hidden_proto (cairo_pop_group); @@ -2519,7 +2530,8 @@ slim_hidden_proto (cairo_scaled_font_get_font_face); slim_hidden_proto (cairo_scaled_font_get_font_matrix); slim_hidden_proto (cairo_scaled_font_get_font_options); slim_hidden_proto (cairo_scaled_font_glyph_extents); -slim_hidden_proto (cairo_scaled_font_reference); +slim_hidden_proto_no_warn (cairo_scaled_font_reference); +slim_hidden_proto (cairo_scaled_font_status); slim_hidden_proto (cairo_set_operator); slim_hidden_proto (cairo_set_source); slim_hidden_proto (cairo_set_source_surface); @@ -2533,7 +2545,7 @@ slim_hidden_proto (cairo_surface_get_device_offset); slim_hidden_proto (cairo_surface_get_font_options); slim_hidden_proto (cairo_surface_get_type); slim_hidden_proto (cairo_surface_mark_dirty_rectangle); -slim_hidden_proto (cairo_surface_reference); +slim_hidden_proto_no_warn (cairo_surface_reference); slim_hidden_proto (cairo_surface_set_device_offset); slim_hidden_proto (cairo_surface_set_fallback_resolution); slim_hidden_proto (cairo_surface_status); diff --git a/src/check-headers.sh b/src/check-headers.sh index 1d0ebf816..2ac74fd21 100755 --- a/src/check-headers.sh +++ b/src/check-headers.sh @@ -12,7 +12,7 @@ xargs grep -B 1 '^cairo_.*[ ]\+(' | awk ' /^--$/ { context=""; public=0; next; } /:cairo_.*[ ]+\(/ { if (!public) {print context; print; print "--";} next; } -/-cairo_public[ ]/ {public=1;} +/-cairo_public.*[ ]/ {public=1;} { context=$0; } ' | sed 's/[.]h-/.h:/' | diff --git a/src/test-fallback-surface.c b/src/test-fallback-surface.c index 628373c6d..0b06dc1fe 100644 --- a/src/test-fallback-surface.c +++ b/src/test-fallback-surface.c @@ -169,6 +169,26 @@ _test_fallback_surface_release_dest_image (void *abstract_surface, image_extra); } +static cairo_status_t +_test_fallback_surface_clone_similar (void *abstract_surface, + cairo_surface_t *src, + int src_x, + int src_y, + int width, + int height, + cairo_surface_t **clone_out) +{ + test_fallback_surface_t *surface = abstract_surface; + + if (src->backend == surface->base.backend) { + *clone_out = cairo_surface_reference (src); + + return CAIRO_STATUS_SUCCESS; + } + + return CAIRO_INT_STATUS_UNSUPPORTED; +} + static cairo_int_status_t _test_fallback_surface_get_extents (void *abstract_surface, cairo_rectangle_int16_t *rectangle) @@ -186,7 +206,7 @@ const cairo_surface_backend_t test_fallback_surface_backend = { _test_fallback_surface_release_source_image, _test_fallback_surface_acquire_dest_image, _test_fallback_surface_release_dest_image, - NULL, /* clone_similar */ + _test_fallback_surface_clone_similar, NULL, /* composite */ NULL, /* fill_rectangles */ NULL, /* composite_trapezoids */ diff --git a/src/test-meta-surface.c b/src/test-meta-surface.c index d686881f1..e2f6a0977 100644 --- a/src/test-meta-surface.c +++ b/src/test-meta-surface.c @@ -144,11 +144,14 @@ static cairo_int_status_t _test_meta_surface_show_page (void *abstract_surface) { test_meta_surface_t *surface = abstract_surface; + cairo_status_t status; if (surface->image_reflects_meta) return CAIRO_STATUS_SUCCESS; - _cairo_meta_surface_replay (surface->meta, surface->image); + status = _cairo_meta_surface_replay (surface->meta, surface->image); + if (status) + return status; surface->image_reflects_meta = TRUE; @@ -280,6 +283,7 @@ static cairo_surface_t * _test_meta_surface_snapshot (void *abstract_other) { test_meta_surface_t *other = abstract_other; + cairo_status_t status; /* XXX: Just making a snapshot of other->meta is what we really * want. But this currently triggers a bug somewhere (the "mask" @@ -299,14 +303,20 @@ _test_meta_surface_snapshot (void *abstract_other) cairo_rectangle_int16_t extents; cairo_surface_t *surface; - _cairo_surface_get_extents (other->image, &extents); + status = _cairo_surface_get_extents (other->image, &extents); + if (status) + return (cairo_surface_t*) &_cairo_surface_nil; surface = cairo_surface_create_similar (other->image, CAIRO_CONTENT_COLOR_ALPHA, 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); + surface = (cairo_surface_t*) &_cairo_surface_nil; + } return surface; #endif diff --git a/test/.gitignore b/test/.gitignore index a6d21da3d..34a300a6f 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -66,6 +66,7 @@ gradient-alpha imagediff infinite-join in-fill-empty-trapezoid +invalid-matrix leaky-dash leaky-polygon line-width diff --git a/test/Makefile.am b/test/Makefile.am index 046185369..d43f77402 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -49,6 +49,7 @@ get-path-extents \ gradient-alpha \ infinite-join \ in-fill-empty-trapezoid \ +invalid-matrix \ leaky-dash \ leaky-polygon \ line-width \ @@ -522,14 +523,16 @@ CLEANFILES = \ $(EXTRA_LTLIBRARIES) \ $(EXTRA_PROGRAMS) -# some systems cannot handle all of our clean files together +# most systems cannot handle all of our clean files together clean-local: - -$(RM) *.ps - -$(RM) *.pdf - -$(RM) *.svg - -$(RM) *-out.png - -$(RM) *-diff.png - -$(RM) *.log + -find . \ + \( -name '*.ps' -print0 \) , \ + \( -name '*.pdf' -print0 \) , \ + \( -name '*.svg' -print0 \) , \ + \( -name '*-out.png' -print0 \) , \ + \( -name '*-diff.png' -print0 \) , \ + \( -name '*.log' -print0 \) \ + | xargs -0 rm -f # Check tests under valgrind # Saves log to valgrind-log diff --git a/test/buffer-diff.c b/test/buffer-diff.c index d111b238b..abb7e33bc 100644 --- a/test/buffer-diff.c +++ b/test/buffer-diff.c @@ -339,6 +339,7 @@ image_diff_core (const char *filename_a, compare_surfaces (surface_a, surface_b, surface_diff, result); + status = CAIRO_STATUS_SUCCESS; if (result->pixels_changed) { FILE *png_file; @@ -347,7 +348,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 +361,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 diff --git a/test/invalid-matrix.c b/test/invalid-matrix.c new file mode 100644 index 000000000..91140a403 --- /dev/null +++ b/test/invalid-matrix.c @@ -0,0 +1,142 @@ +/* + * Copyright © 2007 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Author: Carl Worth <cworth@cworth.org> + */ + +#include "cairo-test.h" + +static cairo_test_draw_function_t draw; + +cairo_test_t test = { + "invalid-matrix", + "Test that all relevant public functions return CAIRO_STATUS_INVALID_MATRIX as appropriate", + 0, 0, + draw +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_status_t status; + cairo_surface_t *target; + cairo_font_face_t *font_face; + cairo_font_options_t *font_options; + cairo_scaled_font_t *scaled_font; + cairo_pattern_t *pattern; + cairo_t *cr2; + cairo_matrix_t identity, invalid = { + 4.0, 4.0, + 4.0, 4.0, + 4.0, 4.0 + }; + +#define CHECK_STATUS(status, function_name) \ +if ((status) == CAIRO_STATUS_SUCCESS) { \ + cairo_test_log ("Error: %s with invalid matrix passed", \ + (function_name)); \ + return CAIRO_TEST_FAILURE; \ +} else if ((status) != CAIRO_STATUS_INVALID_MATRIX) { \ + cairo_test_log ("Warning: %s with invalid matrix returned unexpected status " \ + "(%d): %s\n", \ + (function_name), \ + status, \ + cairo_status_to_string (status)); \ +} + + cairo_matrix_init_identity (&identity); + + target = cairo_get_target (cr); + + /* test cairo_transform with invalid matrix */ + cr2 = cairo_create (target); + cairo_transform (cr2, &invalid); + + status = cairo_status (cr2); + CHECK_STATUS (status,"cairo_transform"); + + cairo_destroy (cr2); + + /* test cairo_set_matrix with invalid matrix */ + cr2 = cairo_create (target); + cairo_set_matrix (cr2, &invalid); + + status = cairo_status (cr2); + CHECK_STATUS (status, "cairo_set_matrix"); + + cairo_destroy (cr2); + + /* test cairo_set_font_matrix with invalid matrix */ + cr2 = cairo_create (target); + cairo_set_font_matrix (cr2, &invalid); + + /* draw some text to force the font to be resolved */ + cairo_show_text (cr2, "hello"); + + status = cairo_status (cr2); + CHECK_STATUS (status, "cairo_set_font_matrix"); + + cairo_destroy (cr2); + + /* test cairo_scaled_font_create with invalid matrix */ + font_face = cairo_get_font_face (cr); + font_options = cairo_font_options_create (); + cairo_get_font_options (cr, font_options); + scaled_font = cairo_scaled_font_create (font_face, + &invalid, + &identity, + font_options); + status = cairo_scaled_font_status (scaled_font); + CHECK_STATUS (status, "cairo_scaled_font_create"); + + cairo_scaled_font_destroy (scaled_font); + + scaled_font = cairo_scaled_font_create (font_face, + &identity, + &invalid, + font_options); + status = cairo_scaled_font_status (scaled_font); + CHECK_STATUS (status, "cairo_scaled_font_create"); + + cairo_scaled_font_destroy (scaled_font); + cairo_font_options_destroy (font_options); + + /* test cairo_pattern_set_matrix with invalid matrix */ + pattern = cairo_pattern_create_rgb (1.0, 1.0, 1.0); + cairo_pattern_set_matrix (pattern, &invalid); + status = cairo_pattern_status (pattern); + CHECK_STATUS (status, "cairo_pattern_set_matrix"); + cairo_pattern_destroy (pattern); + + /* test cairo_matrix_invert with invalid matrix */ + status = cairo_matrix_invert (&invalid); + CHECK_STATUS (status, "cairo_matrix_invert"); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test); +} |