[cairo-commit] src/cairo-truetype-subset.c

Chris Wilson ickle at kemper.freedesktop.org
Thu May 10 13:29:05 PDT 2007


 src/cairo-truetype-subset.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

New commits:
diff-tree c4abc3a0e3ebb27bc0aa178651e496c514eb1fae (from ebababc0cf83f828d48200b8e316f57912fb0128)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu May 10 21:28:48 2007 +0100

    [cairo-truetype-subset] Set CAIRO_STATUS_NO_MEMORY on malloc failure.
    
    _cairo_truetype_font_create() failed to update the status before
    returning after detecting an allocation failure, leaving its callers
    none the wishing - and eventually triggering a segmentation fault when
    the font was used in anger.

diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index 91e618c..f4bb66c 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -939,16 +939,20 @@ _cairo_truetype_subset_init (cairo_truet
 	goto fail1;
 
     truetype_subset->base_font = strdup (font->base.base_font);
-    if (truetype_subset->base_font == NULL)
+    if (truetype_subset->base_font == NULL) {
+	status = CAIRO_STATUS_NO_MEMORY;
 	goto fail1;
+    }
 
     /* The widths array returned must contain only widths for the
      * glyphs in font_subset. Any subglyphs appended after
      * font_subset->num_glyphs are omitted. */
     truetype_subset->widths = calloc (sizeof (double),
                                       font->scaled_font_subset->num_glyphs);
-    if (truetype_subset->widths == NULL)
+    if (truetype_subset->widths == NULL) {
+	status = CAIRO_STATUS_NO_MEMORY;
 	goto fail2;
+    }
     for (i = 0; i < font->scaled_font_subset->num_glyphs; i++)
 	truetype_subset->widths[i] = (double)font->base.widths[i]/font->base.units_per_em;
 
@@ -960,16 +964,20 @@ _cairo_truetype_subset_init (cairo_truet
     truetype_subset->descent = (double)font->base.descent/font->base.units_per_em;
 
     truetype_subset->data = malloc (length);
-    if (truetype_subset->data == NULL)
+    if (truetype_subset->data == NULL) {
+	status = CAIRO_STATUS_NO_MEMORY;
 	goto fail3;
+    }
 
     memcpy (truetype_subset->data, data, length);
     truetype_subset->data_length = length;
 
     offsets_length = num_strings * sizeof (unsigned long);
     truetype_subset->string_offsets = malloc (offsets_length);
-    if (truetype_subset->string_offsets == NULL)
+    if (truetype_subset->string_offsets == NULL) {
+	status = CAIRO_STATUS_NO_MEMORY;
 	goto fail4;
+    }
 
     memcpy (truetype_subset->string_offsets, string_offsets, offsets_length);
     truetype_subset->num_string_offsets = num_strings;


More information about the cairo-commit mailing list