From 869ccac5ab69060f2db2893014b5538539fd4f45 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Thu, 8 Mar 2018 11:06:49 -0800 Subject: [PATCH] [subset] use create_sub_blob instead of manually copying the post table. --- src/hb-ot-post-table.hh | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index cb1e4eb42..c5ad66547 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -84,26 +84,20 @@ struct post inline bool subset (hb_subset_plan_t *plan) const { + unsigned int post_prime_length; hb_blob_t *post_blob = OT::Sanitizer().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_post)); - post *post_table = (post *) hb_blob_get_data (post_blob, nullptr); + hb_blob_t *post_prime_blob = hb_blob_create_sub_blob (post_blob, 0, post::static_size); + post *post_prime = (post *) hb_blob_get_data_writable (post_prime_blob, &post_prime_length); + hb_blob_destroy (post_blob); - post *post_prime = (post *) malloc (post::static_size); - if (unlikely (!post_prime)) + if (unlikely (!post_prime || post_prime_length != post::static_size)) { - hb_blob_destroy (post_blob); - DEBUG_MSG(SUBSET, nullptr, "Unable to alloc %lu for post subset output.", (unsigned long) post::static_size); + hb_blob_destroy (post_prime_blob); + DEBUG_MSG(SUBSET, nullptr, "Invalid source post table with length %d.", post_prime_length); return false; } - memcpy (post_prime, post_table, post::static_size); - hb_blob_destroy (post_blob); - post_prime->version.major.set (3); // Version 3 does not have any glyph names. - hb_blob_t *post_prime_blob = hb_blob_create ((const char *) post_prime, - post::static_size, - HB_MEMORY_MODE_READONLY, - post_prime, - free); bool result = hb_subset_plan_add_table (plan, HB_OT_TAG_post, post_prime_blob); hb_blob_destroy (post_prime_blob);