[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.
This commit is contained in:
Behdad Esfahbod 2022-07-18 22:24:28 -06:00
parent 4279304a62
commit 91c60802e6
1 changed files with 4 additions and 4 deletions

View File

@ -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<Type, OffsetType, has_
{
unsigned int i = (unsigned int) i_;
const OffsetTo<Type, OffsetType, has_null> *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<Type, OffsetType, has_
{
unsigned int i = (unsigned int) i_;
const OffsetTo<Type, OffsetType, has_null> *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;
}