[serialize] Add ran_out_of_room
authorBehdad Esfahbod <behdad@behdad.org>
Sat, 30 Mar 2019 22:06:25 +0000 (15:06 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Sat, 30 Mar 2019 22:06:25 +0000 (15:06 -0700)
src/hb-serialize.hh
src/hb-subset.cc

index f5e4df5..679ae4e 100644 (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;
 };
 
 
index 135265f..b3f0646 100644 (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 ();