From f9d101e747af9d9611229acbcd38b4b40a9ff7b0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 28 Jun 2020 20:59:01 -0700 Subject: [PATCH] m[vector] Recover vector from error in .reset() --- src/hb-vector.hh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 079b94a6b..13517a9c2 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -80,7 +80,12 @@ struct hb_vector_t fini (); } - void reset () { resize (0); } + void reset () + { + if (unlikely (in_error ())) + allocated = length; // Big hack! + resize (0); + } hb_vector_t& operator = (const hb_vector_t &o) { @@ -181,7 +186,7 @@ struct hb_vector_t /* Allocate for size but don't adjust length. */ bool alloc (unsigned int size) { - if (unlikely (allocated < 0)) + if (unlikely (in_error ())) return false; if (likely (size <= (unsigned) allocated)) @@ -195,7 +200,7 @@ struct hb_vector_t Type *new_array = nullptr; bool overflows = - (int) new_allocated < 0 || + (int) in_error () || (new_allocated < (unsigned) allocated) || hb_unsigned_mul_overflows (new_allocated, sizeof (Type)); if (likely (!overflows))