[set] Fix undefined-behavior shift in _previous()

harfbuzz/src/hb-set.hh:138:43: runtime error: shift exponent 64 is too large for 64-bit type 'hb_set_t::page_t::elt_t' (aka 'unsigned long long')
This commit is contained in:
Behdad Esfahbod 2019-11-20 14:22:01 -05:00
parent 5fddc5f169
commit e5c7ee9f75
1 changed files with 5 additions and 1 deletions

View File

@ -135,7 +135,11 @@ struct hb_set_t
unsigned int i = m / ELT_BITS; unsigned int i = m / ELT_BITS;
unsigned int j = m & ELT_MASK; unsigned int j = m & ELT_MASK;
const elt_t vv = v[i] & ((elt_t (1) << (j + 1)) - 1); /* Fancy mask to avoid shifting by elt_t bitsize, which is undefined. */
const elt_t mask = j < 8 * sizeof (elt_t) - 1 ?
((elt_t (1) << (j + 1)) - 1) :
(elt_t) -1;
const elt_t vv = v[i] & mask;
const elt_t *p = &vv; const elt_t *p = &vv;
while (true) while (true)
{ {