mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-09 03:48:03 +02:00
Fix to gracefully handle a NULL pointer for gstate->font
This commit is contained in:
parent
973ee89983
commit
b466e068b9
6 changed files with 108 additions and 36 deletions
15
ChangeLog
15
ChangeLog
|
|
@ -1,3 +1,18 @@
|
|||
2003-10-01 Carl Worth <cworth@isi.edu>
|
||||
|
||||
* src/cairo_gstate.c (_cairo_gstate_init_copy): Don't choke if
|
||||
asked to copy a gstate with a NULL font.
|
||||
|
||||
* src/cairo_font.c (_cairo_font_init):
|
||||
(_cairo_font_init_copy):
|
||||
(_cairo_font_copy):
|
||||
(_cairo_font_fini):
|
||||
(_cairo_font_select):
|
||||
(_cairo_font_scale):
|
||||
(_cairo_font_transform):
|
||||
(_cairo_font_text_extents):
|
||||
(_cairo_font_show_text): Return immediately if passed a NULL pointer.
|
||||
|
||||
2003-09-30 Jamey Sharp <jamey@minilop.net>
|
||||
|
||||
* src/Makefile.am, src/cairo.c, src/cairo.h, src/cairo_font.c,
|
||||
|
|
|
|||
|
|
@ -27,18 +27,26 @@
|
|||
|
||||
#include "cairoint.h"
|
||||
|
||||
void
|
||||
cairo_int_status_t
|
||||
_cairo_font_init (cairo_font_t *font, const struct cairo_font_backend *backend)
|
||||
{
|
||||
if (font == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
font->key = (unsigned char *) strdup (CAIRO_FONT_KEY_DEFAULT);
|
||||
cairo_matrix_set_identity (&font->matrix);
|
||||
|
||||
font->backend = backend;
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
cairo_int_status_t
|
||||
_cairo_font_init_copy (cairo_font_t *font, cairo_font_t *other)
|
||||
{
|
||||
if (other == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
if (other->key) {
|
||||
font->key = (unsigned char *) strdup ((char *) other->key);
|
||||
if (font->key == NULL)
|
||||
|
|
@ -54,8 +62,8 @@ _cairo_font_init_copy (cairo_font_t *font, cairo_font_t *other)
|
|||
cairo_font_t *
|
||||
_cairo_font_copy (cairo_font_t *font)
|
||||
{
|
||||
if (!font->backend->copy)
|
||||
return 0;
|
||||
if (font == NULL || font->backend->copy == NULL)
|
||||
return NULL;
|
||||
|
||||
return font->backend->copy (font);
|
||||
}
|
||||
|
|
@ -63,6 +71,9 @@ _cairo_font_copy (cairo_font_t *font)
|
|||
void
|
||||
_cairo_font_fini (cairo_font_t *font)
|
||||
{
|
||||
if (font == NULL)
|
||||
return;
|
||||
|
||||
if (font->key)
|
||||
free (font->key);
|
||||
font->key = NULL;
|
||||
|
|
@ -73,9 +84,12 @@ _cairo_font_fini (cairo_font_t *font)
|
|||
font->backend->close (font);
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
cairo_int_status_t
|
||||
_cairo_font_select (cairo_font_t *font, const char *key)
|
||||
{
|
||||
if (font == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
if (font->backend->close)
|
||||
font->backend->close (font);
|
||||
|
||||
|
|
@ -89,28 +103,34 @@ _cairo_font_select (cairo_font_t *font, const char *key)
|
|||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
cairo_int_status_t
|
||||
_cairo_font_scale (cairo_font_t *font, double scale)
|
||||
{
|
||||
if (font == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
cairo_matrix_scale (&font->matrix, scale, scale);
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
cairo_int_status_t
|
||||
_cairo_font_transform (cairo_font_t *font,
|
||||
double a, double b,
|
||||
double c, double d)
|
||||
{
|
||||
cairo_matrix_t m;
|
||||
|
||||
if (font == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
cairo_matrix_set_affine (&m, a, b, c, d, 0, 0);
|
||||
cairo_matrix_multiply (&font->matrix, &m, &font->matrix);
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
cairo_int_status_t
|
||||
_cairo_font_text_extents (cairo_font_t *font,
|
||||
cairo_matrix_t *ctm,
|
||||
const unsigned char *utf8,
|
||||
|
|
@ -118,13 +138,16 @@ _cairo_font_text_extents (cairo_font_t *font,
|
|||
double *width, double *height,
|
||||
double *dx, double *dy)
|
||||
{
|
||||
if (font == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
if (!font->backend->text_extents)
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
||||
return font->backend->text_extents (font, ctm, utf8, x, y, width, height, dx, dy);
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
cairo_int_status_t
|
||||
_cairo_font_show_text (cairo_font_t *font,
|
||||
cairo_matrix_t *ctm,
|
||||
cairo_operator_t operator,
|
||||
|
|
@ -134,6 +157,9 @@ _cairo_font_show_text (cairo_font_t *font,
|
|||
double y,
|
||||
const unsigned char *utf8)
|
||||
{
|
||||
if (font == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
if (!font->backend->show_text)
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
||||
|
|
|
|||
|
|
@ -120,11 +120,13 @@ _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other)
|
|||
return CAIRO_STATUS_NO_MEMORY;
|
||||
memcpy (gstate->dash, other->dash, other->num_dashes * sizeof (double));
|
||||
}
|
||||
|
||||
gstate->font = _cairo_font_copy (other->font);
|
||||
if (!gstate->font) {
|
||||
status = CAIRO_STATUS_NO_MEMORY;
|
||||
goto CLEANUP_DASHES;
|
||||
|
||||
if (other->font) {
|
||||
gstate->font = _cairo_font_copy (other->font);
|
||||
if (!gstate->font) {
|
||||
status = CAIRO_STATUS_NO_MEMORY;
|
||||
goto CLEANUP_DASHES;
|
||||
}
|
||||
}
|
||||
|
||||
cairo_surface_reference (gstate->surface);
|
||||
|
|
|
|||
|
|
@ -27,18 +27,26 @@
|
|||
|
||||
#include "cairoint.h"
|
||||
|
||||
void
|
||||
cairo_int_status_t
|
||||
_cairo_font_init (cairo_font_t *font, const struct cairo_font_backend *backend)
|
||||
{
|
||||
if (font == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
font->key = (unsigned char *) strdup (CAIRO_FONT_KEY_DEFAULT);
|
||||
cairo_matrix_set_identity (&font->matrix);
|
||||
|
||||
font->backend = backend;
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
cairo_int_status_t
|
||||
_cairo_font_init_copy (cairo_font_t *font, cairo_font_t *other)
|
||||
{
|
||||
if (other == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
if (other->key) {
|
||||
font->key = (unsigned char *) strdup ((char *) other->key);
|
||||
if (font->key == NULL)
|
||||
|
|
@ -54,8 +62,8 @@ _cairo_font_init_copy (cairo_font_t *font, cairo_font_t *other)
|
|||
cairo_font_t *
|
||||
_cairo_font_copy (cairo_font_t *font)
|
||||
{
|
||||
if (!font->backend->copy)
|
||||
return 0;
|
||||
if (font == NULL || font->backend->copy == NULL)
|
||||
return NULL;
|
||||
|
||||
return font->backend->copy (font);
|
||||
}
|
||||
|
|
@ -63,6 +71,9 @@ _cairo_font_copy (cairo_font_t *font)
|
|||
void
|
||||
_cairo_font_fini (cairo_font_t *font)
|
||||
{
|
||||
if (font == NULL)
|
||||
return;
|
||||
|
||||
if (font->key)
|
||||
free (font->key);
|
||||
font->key = NULL;
|
||||
|
|
@ -73,9 +84,12 @@ _cairo_font_fini (cairo_font_t *font)
|
|||
font->backend->close (font);
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
cairo_int_status_t
|
||||
_cairo_font_select (cairo_font_t *font, const char *key)
|
||||
{
|
||||
if (font == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
if (font->backend->close)
|
||||
font->backend->close (font);
|
||||
|
||||
|
|
@ -89,28 +103,34 @@ _cairo_font_select (cairo_font_t *font, const char *key)
|
|||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
cairo_int_status_t
|
||||
_cairo_font_scale (cairo_font_t *font, double scale)
|
||||
{
|
||||
if (font == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
cairo_matrix_scale (&font->matrix, scale, scale);
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
cairo_int_status_t
|
||||
_cairo_font_transform (cairo_font_t *font,
|
||||
double a, double b,
|
||||
double c, double d)
|
||||
{
|
||||
cairo_matrix_t m;
|
||||
|
||||
if (font == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
cairo_matrix_set_affine (&m, a, b, c, d, 0, 0);
|
||||
cairo_matrix_multiply (&font->matrix, &m, &font->matrix);
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
cairo_int_status_t
|
||||
_cairo_font_text_extents (cairo_font_t *font,
|
||||
cairo_matrix_t *ctm,
|
||||
const unsigned char *utf8,
|
||||
|
|
@ -118,13 +138,16 @@ _cairo_font_text_extents (cairo_font_t *font,
|
|||
double *width, double *height,
|
||||
double *dx, double *dy)
|
||||
{
|
||||
if (font == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
if (!font->backend->text_extents)
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
||||
return font->backend->text_extents (font, ctm, utf8, x, y, width, height, dx, dy);
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
cairo_int_status_t
|
||||
_cairo_font_show_text (cairo_font_t *font,
|
||||
cairo_matrix_t *ctm,
|
||||
cairo_operator_t operator,
|
||||
|
|
@ -134,6 +157,9 @@ _cairo_font_show_text (cairo_font_t *font,
|
|||
double y,
|
||||
const unsigned char *utf8)
|
||||
{
|
||||
if (font == NULL)
|
||||
return CAIRO_INT_STATUS_NULL_POINTER;
|
||||
|
||||
if (!font->backend->show_text)
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
||||
|
|
|
|||
|
|
@ -120,11 +120,13 @@ _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other)
|
|||
return CAIRO_STATUS_NO_MEMORY;
|
||||
memcpy (gstate->dash, other->dash, other->num_dashes * sizeof (double));
|
||||
}
|
||||
|
||||
gstate->font = _cairo_font_copy (other->font);
|
||||
if (!gstate->font) {
|
||||
status = CAIRO_STATUS_NO_MEMORY;
|
||||
goto CLEANUP_DASHES;
|
||||
|
||||
if (other->font) {
|
||||
gstate->font = _cairo_font_copy (other->font);
|
||||
if (!gstate->font) {
|
||||
status = CAIRO_STATUS_NO_MEMORY;
|
||||
goto CLEANUP_DASHES;
|
||||
}
|
||||
}
|
||||
|
||||
cairo_surface_reference (gstate->surface);
|
||||
|
|
|
|||
|
|
@ -128,7 +128,8 @@ typedef struct cairo_rectangle_int {
|
|||
from cairo_status_t. Oh well, without that, I'll use this bogus 1000
|
||||
offset */
|
||||
typedef enum cairo_int_status {
|
||||
CAIRO_INT_STATUS_DEGENERATE = 1000
|
||||
CAIRO_INT_STATUS_DEGENERATE = 1000,
|
||||
CAIRO_INT_STATUS_NULL_POINTER
|
||||
} cairo_int_status_t;
|
||||
|
||||
typedef enum cairo_path_op {
|
||||
|
|
@ -673,10 +674,10 @@ extern void __internal_linkage
|
|||
_cairo_color_set_alpha (cairo_color_t *color, double alpha);
|
||||
|
||||
/* cairo_font.c */
|
||||
extern void __internal_linkage
|
||||
extern cairo_int_status_t __internal_linkage
|
||||
_cairo_font_init (cairo_font_t *font, const struct cairo_font_backend *backend);
|
||||
|
||||
extern cairo_status_t __internal_linkage
|
||||
extern cairo_int_status_t __internal_linkage
|
||||
_cairo_font_init_copy (cairo_font_t *font, cairo_font_t *other);
|
||||
|
||||
extern cairo_font_t * __internal_linkage
|
||||
|
|
@ -685,18 +686,18 @@ _cairo_font_copy (cairo_font_t *font);
|
|||
extern void __internal_linkage
|
||||
_cairo_font_fini (cairo_font_t *font);
|
||||
|
||||
extern cairo_status_t __internal_linkage
|
||||
extern cairo_int_status_t __internal_linkage
|
||||
_cairo_font_select (cairo_font_t *font, const char *key);
|
||||
|
||||
extern cairo_status_t __internal_linkage
|
||||
extern cairo_int_status_t __internal_linkage
|
||||
_cairo_font_scale (cairo_font_t *font, double scale);
|
||||
|
||||
extern cairo_status_t __internal_linkage
|
||||
extern cairo_int_status_t __internal_linkage
|
||||
_cairo_font_transform (cairo_font_t *font,
|
||||
double a, double b,
|
||||
double c, double d);
|
||||
|
||||
extern cairo_status_t __internal_linkage
|
||||
extern cairo_int_status_t __internal_linkage
|
||||
_cairo_font_text_extents (cairo_font_t *font,
|
||||
cairo_matrix_t *ctm,
|
||||
const unsigned char *utf8,
|
||||
|
|
@ -704,7 +705,7 @@ _cairo_font_text_extents (cairo_font_t *font,
|
|||
double *width, double *height,
|
||||
double *dx, double *dy);
|
||||
|
||||
extern cairo_status_t __internal_linkage
|
||||
extern cairo_int_status_t __internal_linkage
|
||||
_cairo_font_show_text (cairo_font_t *font,
|
||||
cairo_matrix_t *ctm,
|
||||
cairo_operator_t operator,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue