mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-28 09:09:13 +01:00
[set] Skip empty pages during reverse iteration (#6332)
Deleting the last member of a page leaves an empty page in the sparse set. `hb_bit_page_t::get_max()` returned zero for that page, so reverse iteration could report a value that was never in the set. For example, add and delete 512, then iterate backward from 1024: HarfBuzz reported 512 from an empty set. Return INVALID for an empty page, matching get_min(), so previous() skips it. Cover reverse scalar/range iteration with retained empty pages, including inverted sets. Assisted-by: OpenAI Codex
This commit is contained in:
1 parent
c22ae24405
commit
3957e16e6c
2 files changed
+39
-1
No files matched your search
+1
-1
@@ -350,7 +350,7 @@ struct hb_bit_page_t
|
||||
for (int i = len () - 1; i >= 0; i--)
|
||||
if (v[i])
|
||||
return i * ELT_BITS + elt_get_max (v[i]);
|
||||
return 0;
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1439,11 +1439,49 @@ test_set_next_previous_range (void)
|
||||
hb_set_destroy (s);
|
||||
}
|
||||
|
||||
static void
|
||||
test_set_previous_empty_pages (void)
|
||||
{
|
||||
hb_set_t *s = hb_set_create ();
|
||||
hb_set_add (s, 512);
|
||||
hb_set_del (s, 512);
|
||||
hb_codepoint_t cp = 1024;
|
||||
g_assert_false (hb_set_previous (s, &cp));
|
||||
g_assert_cmpuint (cp, ==, HB_SET_VALUE_INVALID);
|
||||
|
||||
hb_set_add_range (s, 100, 101);
|
||||
hb_set_add (s, 1536);
|
||||
hb_set_del (s, 1536);
|
||||
cp = 2048;
|
||||
g_assert_true (hb_set_previous (s, &cp));
|
||||
g_assert_cmpuint (cp, ==, 101);
|
||||
g_assert_true (hb_set_previous (s, &cp));
|
||||
g_assert_cmpuint (cp, ==, 100);
|
||||
g_assert_false (hb_set_previous (s, &cp));
|
||||
|
||||
hb_codepoint_t first = 2048, last = 2048;
|
||||
g_assert_true (hb_set_previous_range (s, &first, &last));
|
||||
g_assert_cmpuint (first, ==, 100);
|
||||
g_assert_cmpuint (last, ==, 101);
|
||||
g_assert_false (hb_set_previous_range (s, &first, &last));
|
||||
|
||||
hb_set_invert (s);
|
||||
cp = 1537;
|
||||
g_assert_true (hb_set_previous (s, &cp));
|
||||
g_assert_cmpuint (cp, ==, 1536);
|
||||
first = last = 2048;
|
||||
g_assert_true (hb_set_previous_range (s, &first, &last));
|
||||
g_assert_cmpuint (first, ==, 102);
|
||||
g_assert_cmpuint (last, ==, 2047);
|
||||
hb_set_destroy (s);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
hb_test_init (&argc, &argv);
|
||||
|
||||
hb_test_add (test_set_previous_empty_pages);
|
||||
hb_test_add (test_set_basic);
|
||||
hb_test_add (test_set_next_previous_range);
|
||||
hb_test_add (test_set_subsets);
|
||||
|
||||
Reference in new issue
Block a user