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

Chris Wilson ickle at kemper.freedesktop.org
Wed May 16 08:26:02 PDT 2007


 src/cairo-truetype-subset.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

New commits:
diff-tree c5ae0f1232e8cef860bc1fc0b449ddf9d9063d22 (from e37bee3f52282a042251f2dfc8e051943fd8f1d7)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri May 11 16:11:02 2007 +0100

    [cairo-truetype-subset] Avoid a potential 0 byte allocation.
    
    During _cairo_truetype_subset_init skip copying the string_offsets if
    the vector is empty.

diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index f045410..804eaa8 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -972,16 +972,21 @@ _cairo_truetype_subset_init (cairo_truet
     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) {
-	status = CAIRO_STATUS_NO_MEMORY;
-	goto fail4;
+    if (num_strings) {
+	offsets_length = num_strings * sizeof (unsigned long);
+	truetype_subset->string_offsets = malloc (offsets_length);
+	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;
+    } else {
+	truetype_subset->string_offsets = NULL;
+	truetype_subset->num_string_offsets = 0;
     }
 
-    memcpy (truetype_subset->string_offsets, string_offsets, offsets_length);
-    truetype_subset->num_string_offsets = num_strings;
-
     cairo_truetype_font_destroy (font);
 
     return CAIRO_STATUS_SUCCESS;


More information about the cairo-commit mailing list