From d46bd67c8b3f63d6286845e814f8f1e040f89737 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 10 Apr 2009 14:55:24 +0100 Subject: [PATCH] [type3] Add status checks. Propagate error from the stream when creating the surface and add status guards before writing to the potential nil object. --- src/cairo-type3-glyph-surface.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/cairo-type3-glyph-surface.c b/src/cairo-type3-glyph-surface.c index c52915f77..2ffc01875 100644 --- a/src/cairo-type3-glyph-surface.c +++ b/src/cairo-type3-glyph-surface.c @@ -46,14 +46,17 @@ static const cairo_surface_backend_t cairo_type3_glyph_surface_backend; cairo_surface_t * -_cairo_type3_glyph_surface_create (cairo_scaled_font_t *scaled_font, - cairo_output_stream_t *stream, +_cairo_type3_glyph_surface_create (cairo_scaled_font_t *scaled_font, + cairo_output_stream_t *stream, cairo_type3_glyph_surface_emit_image_t emit_image, - cairo_scaled_font_subsets_t *font_subsets) + cairo_scaled_font_subsets_t *font_subsets) { cairo_type3_glyph_surface_t *surface; cairo_matrix_t invert_y_axis; + if (unlikely (stream != NULL && stream->status)) + return _cairo_surface_create_in_error (stream->status); + surface = malloc (sizeof (cairo_type3_glyph_surface_t)); if (unlikely (surface == NULL)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); @@ -379,6 +382,9 @@ _cairo_type3_glyph_surface_set_font_subsets_callback (void *abstract { cairo_type3_glyph_surface_t *surface = abstract_surface; + if (unlikely (surface->base.status)) + return; + _cairo_pdf_operators_set_font_subsets_callback (&surface->pdf_operators, use_font_subset, closure); @@ -393,7 +399,13 @@ _cairo_type3_glyph_surface_analyze_glyph (void *abstract_surface, cairo_status_t status, status2; cairo_output_stream_t *null_stream; + if (unlikely (surface->base.status)) + return surface->base.status; + null_stream = _cairo_null_stream_create (); + if (unlikely (null_stream->status)) + return null_stream->status; + _cairo_type3_glyph_surface_set_stream (surface, null_stream); _cairo_scaled_font_freeze_cache (surface->scaled_font); @@ -446,6 +458,9 @@ _cairo_type3_glyph_surface_emit_glyph (void *abstract_surface, double x_advance, y_advance; cairo_matrix_t font_matrix_inverse; + if (unlikely (surface->base.status)) + return surface->base.status; + _cairo_type3_glyph_surface_set_stream (surface, stream); _cairo_scaled_font_freeze_cache (surface->scaled_font); @@ -496,6 +511,10 @@ _cairo_type3_glyph_surface_emit_glyph (void *abstract_surface, cairo_output_stream_t *mem_stream; mem_stream = _cairo_memory_stream_create (); + status = mem_stream->status; + if (unlikely (status)) + goto FAIL; + _cairo_type3_glyph_surface_set_stream (surface, mem_stream); _cairo_output_stream_printf (surface->stream, "q\n"); @@ -520,6 +539,7 @@ _cairo_type3_glyph_surface_emit_glyph (void *abstract_surface, if (status == CAIRO_INT_STATUS_IMAGE_FALLBACK) status = _cairo_type3_glyph_surface_emit_fallback_image (surface, glyph_index); + FAIL: _cairo_scaled_font_thaw_cache (surface->scaled_font); return status;