diff --git a/Userland/Libraries/LibGfx/Font/WOFF/Font.cpp b/Userland/Libraries/LibGfx/Font/WOFF/Font.cpp index 38a7e2c0e4..cebd901acc 100644 --- a/Userland/Libraries/LibGfx/Font/WOFF/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/WOFF/Font.cpp @@ -63,10 +63,9 @@ static constexpr u32 WOFF_SIGNATURE = 0x774F4646; static u16 pow_2_less_than_or_equal(u16 x) { - u16 result = 1; - while (result < x) - result <<= 1; - return result; + VERIFY(x > 0); + VERIFY(x < 32769); + return 1 << (sizeof(u16) * 8 - count_leading_zeroes(x - 1)); } ErrorOr> Font::try_load_from_file(DeprecatedString path, unsigned int index) diff --git a/Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp b/Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp index fd24061e16..f3f7c2cb62 100644 --- a/Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp @@ -111,10 +111,9 @@ static i16 be_i16(u8 const* ptr) static u16 pow_2_less_than_or_equal(u16 x) { - u16 result = 1; - while (result < x) - result <<= 1; - return result; + VERIFY(x > 0); + VERIFY(x < 32769); + return 1 << (sizeof(u16) * 8 - count_leading_zeroes(x - 1)); } enum class TransformationVersion {