From c2b151d95262a8dc2d2ce94e19ab0ef5b0c8f98d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 10 Aug 2014 18:52:07 -0400 Subject: [PATCH] Fix hb_in_range() for types smaller than int As exercised by hb-coretext .notdef code. --- src/hb-private.hh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index e97aab6c5..2709c0efe 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -848,7 +848,9 @@ hb_in_range (T u, T lo, T hi) * to generate a warning than unused variables. */ ASSERT_STATIC (sizeof (hb_assert_unsigned_t) >= 0); - return (u - lo) <= (hi - lo); + /* The casts below are important as if T is smaller than int, + * the subtract results will become a signed int! */ + return (T)(u - lo) <= (T)(hi - lo); } template static inline bool