[hb-set] Don't shrink vectors until after processing their contents.

Fixes #1054.
This commit is contained in:
Jonathan Kew 2018-06-11 20:55:14 -07:00 committed by Behdad Esfahbod
parent eb585033ca
commit 82484b05ca
1 changed files with 7 additions and 3 deletions

View File

@ -424,7 +424,7 @@ struct hb_set_t
unsigned int nb = other->pages.len; unsigned int nb = other->pages.len;
unsigned int next_page = na; unsigned int next_page = na;
unsigned int count = 0; unsigned int count = 0, newCount = 0;
unsigned int a = 0, b = 0; unsigned int a = 0, b = 0;
for (; a < na && b < nb; ) for (; a < na && b < nb; )
{ {
@ -452,8 +452,10 @@ struct hb_set_t
if (Op::passthru_right) if (Op::passthru_right)
count += nb - b; count += nb - b;
if (!resize (count)) if (count > pages.len)
return; if (!resize (count))
return;
newCount = count;
/* Process in-place backward. */ /* Process in-place backward. */
a = na; a = na;
@ -506,6 +508,8 @@ struct hb_set_t
page_at (count).v = other->page_at (b).v; page_at (count).v = other->page_at (b).v;
} }
assert (!count); assert (!count);
if (pages.len > newCount)
resize (newCount);
} }
inline void union_ (const hb_set_t *other) inline void union_ (const hb_set_t *other)