From e5c7ee9f757baa166a96d73b7ec0cb2b1ae23385 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 20 Nov 2019 14:22:01 -0500 Subject: [PATCH] [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') --- src/hb-set.hh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hb-set.hh b/src/hb-set.hh index 7603526e7..21cb17200 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -135,7 +135,11 @@ struct hb_set_t unsigned int i = m / ELT_BITS; 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; while (true) {