[vector] Keep allocated size when in error

This commit is contained in:
Behdad Esfahbod 2023-06-08 12:08:29 -06:00
parent 9df07c3c30
commit dbdeb2649d

View file

@ -86,7 +86,7 @@ struct hb_vector_t
~hb_vector_t () { fini (); }
public:
int allocated = 0; /* == -1 means allocation failed. */
int allocated = 0; /* < 0 means allocation failed. */
unsigned int length = 0;
public:
Type *arrayZ = nullptr;
@ -116,11 +116,7 @@ struct hb_vector_t
void reset ()
{
if (unlikely (in_error ()))
/* Big Hack! We don't know the true allocated size before
* an allocation failure happened. But we know it was at
* least as big as length. Restore it to that and continue
* as if error did not happen. */
allocated = length;
allocated = -allocated;
resize (0);
}
@ -396,7 +392,7 @@ struct hb_vector_t
if (unlikely (overflows))
{
allocated = -1;
allocated = -allocated;
return false;
}
@ -407,7 +403,7 @@ struct hb_vector_t
if (new_allocated <= (unsigned) allocated)
return true; // shrinking failed; it's okay; happens in our fuzzer
allocated = -1;
allocated = -allocated;
return false;
}