mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-07 09:48:03 +02:00
[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.
This commit is contained in:
parent
0f0e2d7384
commit
21d1138da9
1 changed files with 35 additions and 28 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue