diff --git a/src/hb-array.hh b/src/hb-array.hh index 2275ac003..67cfa454e 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -272,7 +272,7 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> { TRACE_SERIALIZE (this); auto* out = c->start_embed (arrayZ); - if (unlikely (!c->extend_size (out, get_size ()))) return_trace (hb_array_t ()); + if (unlikely (!c->extend_size (out, get_size (), false))) return_trace (hb_array_t ()); for (unsigned i = 0; i < length; i++) out[i] = arrayZ[i]; /* TODO: add version that calls c->copy() */ return_trace (hb_array_t (out, length)); @@ -285,7 +285,7 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> { TRACE_SERIALIZE (this); auto* out = c->start_embed (arrayZ); - if (unlikely (!c->extend_size (out, get_size ()))) return_trace (hb_array_t ()); + if (unlikely (!c->extend_size (out, get_size (), false))) return_trace (hb_array_t ()); hb_memcpy (out, arrayZ, length); return_trace (hb_array_t (out, length)); } diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index a48107bb3..5461de36f 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -571,7 +571,7 @@ struct hb_serialize_context_t } template - Type *allocate_size (size_t size) + Type *allocate_size (size_t size, bool clear = true) { if (unlikely (in_error ())) return nullptr; @@ -580,7 +580,8 @@ struct hb_serialize_context_t err (HB_SERIALIZE_ERROR_OUT_OF_ROOM); return nullptr; } - hb_memset (this->head, 0, size); + if (clear) + hb_memset (this->head, 0, size); char *ret = this->head; this->head += size; return reinterpret_cast (ret); @@ -635,7 +636,7 @@ struct hb_serialize_context_t hb_serialize_context_t& operator << (const Type &obj) & { embed (obj); return *this; } template - Type *extend_size (Type *obj, size_t size) + Type *extend_size (Type *obj, size_t size, bool clear = true) { if (unlikely (in_error ())) return nullptr; @@ -643,12 +644,12 @@ struct hb_serialize_context_t assert ((char *) obj <= this->head); assert ((size_t) (this->head - (char *) obj) <= size); if (unlikely (((char *) obj + size < (char *) obj) || - !this->allocate_size (((char *) obj) + size - this->head))) return nullptr; + !this->allocate_size (((char *) obj) + size - this->head, clear))) return nullptr; return reinterpret_cast (obj); } template - Type *extend_size (Type &obj, size_t size) - { return extend_size (std::addressof (obj), size); } + Type *extend_size (Type &obj, size_t size, bool clear = true) + { return extend_size (std::addressof (obj), size, clear); } template Type *extend_min (Type *obj) { return extend_size (obj, obj->min_size); }