From 91c60802e646ee10daa8eda0ab2d2ea06206cc41 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 18 Jul 2022 22:24:28 -0600 Subject: [PATCH] [open-type] Fix overflow check Without the cast, the compiler is within its rights to reason that overflow didn't happen and optimize away the check, as clang was. --- src/hb-open-type.hh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index bc43de7c3..d0d01a68c 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -458,7 +458,7 @@ struct UnsizedArrayOf { unsigned int i = (unsigned int) i_; const Type *p = &arrayZ[i]; - if (unlikely (p < arrayZ)) return Null (Type); /* Overflowed. */ + if (unlikely ((const void *) p < (const void *) arrayZ)) return Null (Type); /* Overflowed. */ _hb_compiler_memory_r_barrier (); return *p; } @@ -466,7 +466,7 @@ struct UnsizedArrayOf { unsigned int i = (unsigned int) i_; Type *p = &arrayZ[i]; - if (unlikely (p < arrayZ)) return Crap (Type); /* Overflowed. */ + if (unlikely ((const void *) p < (const void *) arrayZ)) return Crap (Type); /* Overflowed. */ _hb_compiler_memory_r_barrier (); return *p; } @@ -560,7 +560,7 @@ struct UnsizedListOfOffset16To : UnsizedArray16OfOffsetTo *p = &this->arrayZ[i]; - if (unlikely (p < this->arrayZ)) return Null (Type); /* Overflowed. */ + if (unlikely ((const void *) p < (const void *) this->arrayZ)) return Null (Type); /* Overflowed. */ _hb_compiler_memory_r_barrier (); return this+*p; } @@ -568,7 +568,7 @@ struct UnsizedListOfOffset16To : UnsizedArray16OfOffsetTo *p = &this->arrayZ[i]; - if (unlikely (p < this->arrayZ)) return Crap (Type); /* Overflowed. */ + if (unlikely ((const void *) p < (const void *) this->arrayZ)) return Crap (Type); /* Overflowed. */ _hb_compiler_memory_r_barrier (); return this+*p; }