[serialize] Add ran_out_of_room

This commit is contained in:
Behdad Esfahbod 2019-03-30 15:06:25 -07:00
parent a7c63cd8f8
commit fe05e48086
2 changed files with 13 additions and 2 deletions

View File

@ -51,6 +51,7 @@ struct hb_serialize_context_t
void reset ()
{
this->successful = true;
this->ran_out_of_room = false;
this->head = this->start;
this->debug_depth = 0;
}
@ -111,7 +112,11 @@ struct hb_serialize_context_t
template <typename Type>
Type *allocate_size (unsigned int size)
{
if (unlikely (!this->successful || this->end - this->head < ptrdiff_t (size))) {
if (unlikely (!this->successful)) return nullptr;
if (this->end - this->head < ptrdiff_t (size))
{
this->ran_out_of_room = true;
this->successful = false;
return nullptr;
}
@ -190,6 +195,7 @@ struct hb_serialize_context_t
unsigned int debug_depth;
char *start, *end, *head;
bool successful;
bool ran_out_of_room;
};

View File

@ -83,7 +83,7 @@ _subset2 (hb_subset_plan_t *plan)
hb_serialize_context_t serializer ((void *) buf, buf_size);
hb_subset_context_t c (plan, &serializer);
result = table->subset (&c);
if (serializer.in_error ())
if (serializer.ran_out_of_room)
{
buf_size += (buf_size >> 1) + 32;
DEBUG_MSG(SUBSET, nullptr, "OT::%c%c%c%c ran out of room; reallocating to %u bytes.", HB_UNTAG (tag), buf_size);
@ -94,6 +94,11 @@ _subset2 (hb_subset_plan_t *plan)
}
goto retry;
}
if (serializer.in_error ())
{
abort ();
}
if (result)
{
hb_blob_t *dest_blob = serializer.copy_blob ();