summaryrefslogtreecommitdiff
path: root/src/cairo-scaled-font-subsets.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2009-04-10 14:53:55 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2009-04-16 09:34:03 +0100
commit21d1138da9bcf9c006e0cf3f3d1d50e1c7cec1de (patch)
tree640ee2bb12619b81c11a3a8b6119b051c21dc4cc /src/cairo-scaled-font-subsets.c
parent0f0e2d738437176e72317b37ef66fbc56c60ba93 (diff)
downloadcairo-21d1138da9bcf9c006e0cf3f3d1d50e1c7cec1de.tar.gz
[scaled-font-subsets] Check for malloc failure.
Check that the utf8 string is successfully allocated before writing to it, otherwise propagate the error status back to the callers.
Diffstat (limited to 'src/cairo-scaled-font-subsets.c')
-rw-r--r--src/cairo-scaled-font-subsets.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/src/cairo-scaled-font-subsets.c b/src/cairo-scaled-font-subsets.c
index 44e850e4a..02b32aa7f 100644
--- a/src/cairo-scaled-font-subsets.c
+++ b/src/cairo-scaled-font-subsets.c
@@ -372,13 +372,16 @@ _cairo_sub_font_glyph_lookup_unicode (cairo_sub_font_glyph_t *sub_font_glyph,
return CAIRO_STATUS_SUCCESS;
}
-static cairo_bool_t
+static cairo_status_t
_cairo_sub_font_glyph_map_to_unicode (cairo_sub_font_glyph_t *sub_font_glyph,
const char *utf8,
- int utf8_len)
+ int utf8_len,
+ cairo_bool_t *is_mapped)
{
+ *is_mapped = FALSE;
+
if (utf8_len < 0)
- return FALSE;
+ return CAIRO_STATUS_SUCCESS;
if (utf8 != NULL && utf8_len != 0 && utf8[utf8_len - 1] == '\0')
utf8_len--;
@@ -389,28 +392,25 @@ _cairo_sub_font_glyph_map_to_unicode (cairo_sub_font_glyph_t *sub_font_glyph,
memcmp (utf8, sub_font_glyph->utf8, utf8_len) == 0)
{
/* Requested utf8 mapping matches the existing mapping */
- return TRUE;
- }
- else
- {
- /* Requested utf8 mapping does not match the existing mapping */
- return FALSE;
+ *is_mapped = TRUE;
}
} else {
/* No existing mapping. Use the requested mapping */
sub_font_glyph->utf8 = malloc (utf8_len + 1);
+ if (unlikely (sub_font_glyph->utf8 == NULL))
+ return CAIRO_STATUS_NO_MEMORY;
+
memcpy (sub_font_glyph->utf8, utf8, utf8_len);
sub_font_glyph->utf8[utf8_len] = 0;
sub_font_glyph->utf8_len = utf8_len;
- return TRUE;
+ *is_mapped = TRUE;
}
}
- /* No mapping was requested. */
- return FALSE;
+ return CAIRO_STATUS_SUCCESS;
}
-static cairo_bool_t
+static cairo_int_status_t
_cairo_sub_font_lookup_glyph (cairo_sub_font_t *sub_font,
unsigned long scaled_font_glyph_index,
const char *utf8,
@@ -418,6 +418,7 @@ _cairo_sub_font_lookup_glyph (cairo_sub_font_t *sub_font,
cairo_scaled_font_subsets_glyph_t *subset_glyph)
{
cairo_sub_font_glyph_t key, *sub_font_glyph;
+ cairo_int_status_t status;
_cairo_sub_font_glyph_init_key (&key, scaled_font_glyph_index);
sub_font_glyph = _cairo_hash_table_lookup (sub_font->sub_font_glyphs,
@@ -430,13 +431,15 @@ _cairo_sub_font_lookup_glyph (cairo_sub_font_t *sub_font,
subset_glyph->is_composite = sub_font->is_composite;
subset_glyph->x_advance = sub_font_glyph->x_advance;
subset_glyph->y_advance = sub_font_glyph->y_advance;
- subset_glyph->utf8_is_mapped = _cairo_sub_font_glyph_map_to_unicode (sub_font_glyph, utf8, utf8_len);
+ status = _cairo_sub_font_glyph_map_to_unicode (sub_font_glyph,
+ utf8, utf8_len,
+ &subset_glyph->utf8_is_mapped);
subset_glyph->unicode = sub_font_glyph->unicode;
- return TRUE;
+ return status;
}
- return FALSE;
+ return CAIRO_INT_STATUS_UNSUPPORTED;
}
static cairo_status_t
@@ -524,10 +527,12 @@ _cairo_sub_font_map_glyph (cairo_sub_font_t *sub_font,
subset_glyph->is_composite = sub_font->is_composite;
subset_glyph->x_advance = sub_font_glyph->x_advance;
subset_glyph->y_advance = sub_font_glyph->y_advance;
- subset_glyph->utf8_is_mapped = _cairo_sub_font_glyph_map_to_unicode (sub_font_glyph, utf8, utf8_len);
+ status = _cairo_sub_font_glyph_map_to_unicode (sub_font_glyph,
+ utf8, utf8_len,
+ &subset_glyph->utf8_is_mapped);
subset_glyph->unicode = sub_font_glyph->unicode;
- return CAIRO_STATUS_SUCCESS;
+ return status;
}
static void
@@ -686,11 +691,12 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t *subsets,
sub_font = _cairo_hash_table_lookup (subsets->unscaled_sub_fonts,
&key.base);
if (sub_font != NULL) {
- if (_cairo_sub_font_lookup_glyph (sub_font,
- scaled_font_glyph_index,
- utf8, utf8_len,
- subset_glyph))
- return CAIRO_STATUS_SUCCESS;
+ status = _cairo_sub_font_lookup_glyph (sub_font,
+ scaled_font_glyph_index,
+ utf8, utf8_len,
+ subset_glyph);
+ if (status != CAIRO_INT_STATUS_UNSUPPORTED)
+ return status;
}
}
@@ -700,11 +706,12 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t *subsets,
sub_font = _cairo_hash_table_lookup (subsets->scaled_sub_fonts,
&key.base);
if (sub_font != NULL) {
- if (_cairo_sub_font_lookup_glyph (sub_font,
- scaled_font_glyph_index,
- utf8, utf8_len,
- subset_glyph))
- return CAIRO_STATUS_SUCCESS;
+ status = _cairo_sub_font_lookup_glyph (sub_font,
+ scaled_font_glyph_index,
+ utf8, utf8_len,
+ subset_glyph);
+ if (status != CAIRO_INT_STATUS_UNSUPPORTED)
+ return status;
}
/* Glyph not found. Determine whether the glyph is outline or