m[vector] Recover vector from error in .reset()
This commit is contained in:
parent
5e76ddf54d
commit
f9d101e747
|
@ -80,7 +80,12 @@ struct hb_vector_t
|
||||||
fini ();
|
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)
|
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. */
|
/* Allocate for size but don't adjust length. */
|
||||||
bool alloc (unsigned int size)
|
bool alloc (unsigned int size)
|
||||||
{
|
{
|
||||||
if (unlikely (allocated < 0))
|
if (unlikely (in_error ()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (likely (size <= (unsigned) allocated))
|
if (likely (size <= (unsigned) allocated))
|
||||||
|
@ -195,7 +200,7 @@ struct hb_vector_t
|
||||||
|
|
||||||
Type *new_array = nullptr;
|
Type *new_array = nullptr;
|
||||||
bool overflows =
|
bool overflows =
|
||||||
(int) new_allocated < 0 ||
|
(int) in_error () ||
|
||||||
(new_allocated < (unsigned) allocated) ||
|
(new_allocated < (unsigned) allocated) ||
|
||||||
hb_unsigned_mul_overflows (new_allocated, sizeof (Type));
|
hb_unsigned_mul_overflows (new_allocated, sizeof (Type));
|
||||||
if (likely (!overflows))
|
if (likely (!overflows))
|
||||||
|
|
Loading…
Reference in New Issue