From df827a6ab88cd8bde346176fc53a5c2d57eee808 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Oct 2018 11:34:20 +0200 Subject: [PATCH] [cache] Fix cache coherency corner-case If key_bits+value_bits-cache_bits==32 then -1 is ambiguous... --- src/hb-cache.hh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hb-cache.hh b/src/hb-cache.hh index ec2e8635f..70e966e8d 100644 --- a/src/hb-cache.hh +++ b/src/hb-cache.hh @@ -36,7 +36,8 @@ template = cache_bits), ""); - static_assert ((key_bits + value_bits - cache_bits <= 8 * sizeof (unsigned int)), ""); + static_assert ((key_bits + value_bits - cache_bits <= 8 * sizeof (hb_atomic_int_t)), ""); + static_assert (sizeof (hb_atomic_int_t) == sizeof (unsigned int)); inline void init (void) { clear (); } inline void fini (void) {} @@ -51,7 +52,8 @@ struct hb_cache_t { unsigned int k = key & ((1u<> value_bits) != (key >> cache_bits)) + if ((key_bits + value_bits - cache_bits == 8 * sizeof (hb_atomic_int_t) && v == (unsigned int) -1) || + (v >> value_bits) != (key >> cache_bits)) return false; *value = v & ((1u<