[set] In add_sorted_array(), bail if data is not sorted

This commit is contained in:
Behdad Esfahbod 2017-12-16 11:49:39 -05:00
parent a7bd6d7a4c
commit 493a005d95
1 changed files with 6 additions and 2 deletions

View File

@ -286,20 +286,24 @@ struct hb_set_t
if (unlikely (in_error)) return false;
if (!count) return true;
hb_codepoint_t g = *array;
hb_codepoint_t last_g = g;
while (count)
{
unsigned int m = get_major (g);
page_t *page = page_for_insert (g); if (unlikely (!page)) return false;
unsigned int start = major_start (m);
unsigned int end = major_start (m + 1);
do
{
/* If we try harder we can change the following comparison to <=;
* Not sure if it's worth it. */
if (g < last_g) return false;
last_g = g;
page->add (g);
array++;
count--;
}
while (count && (g = *array, start <= g && g < end));
while (count && (g = *array, g < end));
}
return true;
}