Fixes from David Reveman with minor cleanups by Carl Worth:

Handle new failure possibility of _cairo_gstate_init. (_cairo_gstate_init): Handle possible failure of _cairo_pattern_create_solid. (_cairo_gstate_set_pattern): Reference new pattern before destroying existing pattern to handle the case where they are the same. (_cairo_gstate_set_rgb_color): Handle possible failure of _cairo_pattern_create_solid.
This commit is contained in:
Carl Worth 2005-02-24 12:28:51 +00:00
parent 12d19423f6
commit 04fefd1b28
4 changed files with 51 additions and 13 deletions

View file

@ -1,3 +1,17 @@
2005-02-24 Carl Worth <cworth@cworth.org>
Fixes from David Reveman with minor cleanups by Carl Worth:
* src/cairo_gstate.c (_cairo_gstate_create): Handle new failure
possibility of _cairo_gstate_init.
(_cairo_gstate_init): Handle possible failure of
_cairo_pattern_create_solid.
(_cairo_gstate_set_pattern): Reference new pattern before
destroying existing pattern to handle the case where they are the
same.
(_cairo_gstate_set_rgb_color): Handle possible failure of
_cairo_pattern_create_solid.
2005-02-24 Carl Worth <cworth@cworth.org>
* src/cairo.h: Fix typo (pointed out by Kristian Høgsberg).

View file

@ -55,17 +55,24 @@ _cairo_gstate_unset_font (cairo_gstate_t *gstate);
cairo_gstate_t *
_cairo_gstate_create ()
{
cairo_status_t status;
cairo_gstate_t *gstate;
gstate = malloc (sizeof (cairo_gstate_t));
if (gstate)
_cairo_gstate_init (gstate);
{
status = _cairo_gstate_init (gstate);
if (status) {
free (gstate);
return NULL;
}
}
return gstate;
}
void
cairo_status_t
_cairo_gstate_init (cairo_gstate_t *gstate)
{
gstate->operator = CAIRO_GSTATE_OPERATOR_DEFAULT;
@ -95,6 +102,9 @@ _cairo_gstate_init (cairo_gstate_t *gstate)
gstate->clip.surface = NULL;
gstate->pattern = _cairo_pattern_create_solid (0.0, 0.0, 0.0);
if (!gstate->pattern)
return CAIRO_STATUS_NO_MEMORY;
gstate->alpha = 1.0;
gstate->pixels_per_inch = CAIRO_GSTATE_PIXELS_PER_INCH_DEFAULT;
@ -105,6 +115,8 @@ _cairo_gstate_init (cairo_gstate_t *gstate)
_cairo_pen_init_empty (&gstate->pen_regular);
gstate->next = NULL;
return CAIRO_STATUS_SUCCESS;
}
cairo_status_t
@ -392,11 +404,9 @@ _cairo_gstate_set_pattern (cairo_gstate_t *gstate, cairo_pattern_t *pattern)
if (pattern == NULL)
return CAIRO_STATUS_NULL_POINTER;
if (gstate->pattern)
cairo_pattern_destroy (gstate->pattern);
gstate->pattern = pattern;
cairo_pattern_reference (pattern);
cairo_pattern_destroy (gstate->pattern);
gstate->pattern = pattern;
return CAIRO_STATUS_SUCCESS;
}
@ -434,6 +444,8 @@ _cairo_gstate_set_rgb_color (cairo_gstate_t *gstate, double red, double green, d
cairo_pattern_destroy (gstate->pattern);
gstate->pattern = _cairo_pattern_create_solid (red, green, blue);
if (!gstate->pattern)
return CAIRO_STATUS_NO_MEMORY;
return CAIRO_STATUS_SUCCESS;
}

View file

@ -55,17 +55,24 @@ _cairo_gstate_unset_font (cairo_gstate_t *gstate);
cairo_gstate_t *
_cairo_gstate_create ()
{
cairo_status_t status;
cairo_gstate_t *gstate;
gstate = malloc (sizeof (cairo_gstate_t));
if (gstate)
_cairo_gstate_init (gstate);
{
status = _cairo_gstate_init (gstate);
if (status) {
free (gstate);
return NULL;
}
}
return gstate;
}
void
cairo_status_t
_cairo_gstate_init (cairo_gstate_t *gstate)
{
gstate->operator = CAIRO_GSTATE_OPERATOR_DEFAULT;
@ -95,6 +102,9 @@ _cairo_gstate_init (cairo_gstate_t *gstate)
gstate->clip.surface = NULL;
gstate->pattern = _cairo_pattern_create_solid (0.0, 0.0, 0.0);
if (!gstate->pattern)
return CAIRO_STATUS_NO_MEMORY;
gstate->alpha = 1.0;
gstate->pixels_per_inch = CAIRO_GSTATE_PIXELS_PER_INCH_DEFAULT;
@ -105,6 +115,8 @@ _cairo_gstate_init (cairo_gstate_t *gstate)
_cairo_pen_init_empty (&gstate->pen_regular);
gstate->next = NULL;
return CAIRO_STATUS_SUCCESS;
}
cairo_status_t
@ -392,11 +404,9 @@ _cairo_gstate_set_pattern (cairo_gstate_t *gstate, cairo_pattern_t *pattern)
if (pattern == NULL)
return CAIRO_STATUS_NULL_POINTER;
if (gstate->pattern)
cairo_pattern_destroy (gstate->pattern);
gstate->pattern = pattern;
cairo_pattern_reference (pattern);
cairo_pattern_destroy (gstate->pattern);
gstate->pattern = pattern;
return CAIRO_STATUS_SUCCESS;
}
@ -434,6 +444,8 @@ _cairo_gstate_set_rgb_color (cairo_gstate_t *gstate, double red, double green, d
cairo_pattern_destroy (gstate->pattern);
gstate->pattern = _cairo_pattern_create_solid (red, green, blue);
if (!gstate->pattern)
return CAIRO_STATUS_NO_MEMORY;
return CAIRO_STATUS_SUCCESS;
}

View file

@ -926,7 +926,7 @@ _cairo_fixed_integer_ceil (cairo_fixed_t f);
cairo_private cairo_gstate_t *
_cairo_gstate_create (void);
cairo_private void
cairo_private cairo_status_t
_cairo_gstate_init (cairo_gstate_t *gstate);
cairo_private cairo_status_t