[subset] bail out of subsetting if plan allocation fails.

This commit is contained in:
Garret Rieger 2020-07-28 18:31:46 -07:00 committed by Ebrahim Byagowi
parent d38d63319b
commit dae32b4f12
4 changed files with 17 additions and 1 deletions

View File

@ -721,7 +721,10 @@ hb_face_builder_add_table (hb_face_t *face, hb_tag_t tag, hb_blob_t *blob)
return false; return false;
hb_face_builder_data_t *data = (hb_face_builder_data_t *) face->user_data; hb_face_builder_data_t *data = (hb_face_builder_data_t *) face->user_data;
hb_face_builder_data_t::table_entry_t *entry = data->tables.push (); hb_face_builder_data_t::table_entry_t *entry = data->tables.push ();
if (data->tables.in_error())
return false;
entry->tag = tag; entry->tag = tag;
entry->blob = hb_blob_reference (blob); entry->blob = hb_blob_reference (blob);

View File

@ -314,8 +314,12 @@ hb_subset_plan_t *
hb_subset_plan_create (hb_face_t *face, hb_subset_plan_create (hb_face_t *face,
hb_subset_input_t *input) hb_subset_input_t *input)
{ {
hb_subset_plan_t *plan = hb_object_create<hb_subset_plan_t> (); hb_subset_plan_t *plan;
if (unlikely (!(plan = hb_object_create<hb_subset_plan_t> ()))) {
return const_cast<hb_subset_plan_t *> (&Null (hb_subset_plan_t));
}
plan->successful = true;
plan->drop_hints = input->drop_hints; plan->drop_hints = input->drop_hints;
plan->desubroutinize = input->desubroutinize; plan->desubroutinize = input->desubroutinize;
plan->retain_gids = input->retain_gids; plan->retain_gids = input->retain_gids;

View File

@ -39,6 +39,7 @@ struct hb_subset_plan_t
{ {
hb_object_header_t header; hb_object_header_t header;
bool successful : 1;
bool drop_hints : 1; bool drop_hints : 1;
bool desubroutinize : 1; bool desubroutinize : 1;
bool retain_gids : 1; bool retain_gids : 1;
@ -89,6 +90,11 @@ struct hb_subset_plan_t
public: public:
bool in_error () const
{
return !successful;
}
/* /*
* The set of input glyph ids which will be retained in the subset. * The set of input glyph ids which will be retained in the subset.
* Does NOT include ids kept due to retain_gids. You probably want to use * Does NOT include ids kept due to retain_gids. You probably want to use

View File

@ -241,6 +241,8 @@ hb_subset (hb_face_t *source, hb_subset_input_t *input)
if (unlikely (!input || !source)) return hb_face_get_empty (); if (unlikely (!input || !source)) return hb_face_get_empty ();
hb_subset_plan_t *plan = hb_subset_plan_create (source, input); hb_subset_plan_t *plan = hb_subset_plan_create (source, input);
if (unlikely (plan->in_error ()))
return hb_face_get_empty ();
hb_set_t tags_set; hb_set_t tags_set;
bool success = true; bool success = true;
@ -261,6 +263,7 @@ hb_subset (hb_face_t *source, hb_subset_input_t *input)
end: end:
hb_face_t *result = success ? hb_face_reference (plan->dest) : hb_face_get_empty (); hb_face_t *result = success ? hb_face_reference (plan->dest) : hb_face_get_empty ();
hb_subset_plan_destroy (plan); hb_subset_plan_destroy (plan);
return result; return result;
} }