[cairo-scaled-font] Check for allocation failure.

cairo_scaled_font_create() returns a nil object on failure whereas a few
callers were checking for NULL.

Secondly review the public entry points for cairo_scaled_font_*() to
ensure that all check that they will not attempt to overwrite the
read-only nil object.
This commit is contained in:
Chris Wilson 2007-05-10 17:17:30 +01:00
parent aec92188f1
commit ab6a767cf4
4 changed files with 14 additions and 7 deletions

View file

@ -1464,11 +1464,10 @@ _cairo_gstate_ensure_scaled_font (cairo_gstate_t *gstate)
&gstate->font_matrix,
&gstate->ctm,
&options);
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);
status = cairo_scaled_font_status (gstate->scaled_font);
if (status)
return status;
return CAIRO_STATUS_SUCCESS;
}

View file

@ -531,6 +531,8 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t *subsets,
&identity,
&identity,
&font_options);
if (unscaled_font->status)
return unscaled_font->status;
subset_glyph->is_scaled = FALSE;
type1_font = FALSE;

View file

@ -135,6 +135,9 @@ _cairo_scaled_font_set_error (cairo_scaled_font_t *scaled_font,
cairo_font_type_t
cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font)
{
if (scaled_font->ref_count == CAIRO_REF_COUNT_INVALID)
return CAIRO_FONT_TYPE_TOY;
return scaled_font->backend->type;
}
@ -770,10 +773,13 @@ cairo_scaled_font_text_extents (cairo_scaled_font_t *scaled_font,
const char *utf8,
cairo_text_extents_t *extents)
{
cairo_status_t status = CAIRO_STATUS_SUCCESS;
cairo_status_t status;
cairo_glyph_t *glyphs;
int num_glyphs;
if (scaled_font->status)
return;
status = _cairo_scaled_font_text_to_glyphs (scaled_font, 0., 0., utf8, &glyphs, &num_glyphs);
if (status) {
_cairo_scaled_font_set_error (scaled_font, status);
@ -807,7 +813,7 @@ cairo_scaled_font_glyph_extents (cairo_scaled_font_t *scaled_font,
int num_glyphs,
cairo_text_extents_t *extents)
{
cairo_status_t status = CAIRO_STATUS_SUCCESS;
cairo_status_t status;
int i;
double min_x = 0.0, min_y = 0.0, max_x = 0.0, max_y = 0.0;
cairo_bool_t visible = FALSE;

View file

@ -106,7 +106,7 @@ cairo_type1_font_create (cairo_scaled_font_subset_t *scaled_font_subset,
&font_matrix,
&ctm,
&font_options);
if (font->type1_scaled_font == NULL)
if (font->type1_scaled_font->status)
goto fail;
_cairo_array_init (&font->contents, sizeof (unsigned char));