From 8d8bcde8cfe214855fdde15b5d9448e87d3ec734 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 15 Mar 2023 17:29:08 +0000 Subject: [PATCH] [set] don't allow -1 (HB_SET_VALUE_INVALID) to be inserted into a hb_set_t. Add tests that check all of the addition methods. --- src/hb-bit-set.hh | 4 ++-- src/test-set.cc | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index 475b07b81..c30b2af7b 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -194,7 +194,7 @@ struct hb_bit_set_t unsigned int end = major_start (m + 1); do { - if (v || page) /* The v check is to optimize out the page check if v is true. */ + if (g != INVALID && (v || page)) /* The v check is to optimize out the page check if v is true. */ page->set (g, v); array = &StructAtOffsetUnaligned (array, stride); @@ -238,7 +238,7 @@ struct hb_bit_set_t if (g < last_g) return false; last_g = g; - if (v || page) /* The v check is to optimize out the page check if v is true. */ + if (g != INVALID && (v || page)) /* The v check is to optimize out the page check if v is true. */ page->add (g); array = &StructAtOffsetUnaligned (array, stride); diff --git a/src/test-set.cc b/src/test-set.cc index 9fe319da6..5f13ab322 100644 --- a/src/test-set.cc +++ b/src/test-set.cc @@ -137,5 +137,29 @@ main (int argc, char **argv) assert (s.has (HB_SET_VALUE_INVALID)); } + /* Adding HB_SET_VALUE_INVALID */ + { + hb_set_t s; + + s.add(HB_SET_VALUE_INVALID); + assert(!s.has(HB_SET_VALUE_INVALID)); + + s.clear(); + assert(!s.add_range(HB_SET_VALUE_INVALID - 2, HB_SET_VALUE_INVALID)); + assert(!s.has(HB_SET_VALUE_INVALID)); + + hb_codepoint_t array[] = {(unsigned) HB_SET_VALUE_INVALID, 0, 2}; + s.clear(); + s.add_array(array, 3); + assert(!s.has(HB_SET_VALUE_INVALID)); + assert(s.has(2)); + + hb_codepoint_t sorted_array[] = {0, 2, (unsigned) HB_SET_VALUE_INVALID}; + s.clear(); + s.add_sorted_array(sorted_array, 3); + assert(!s.has(HB_SET_VALUE_INVALID)); + assert(s.has(2)); + } + return 0; }