1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:57:45 +00:00

LibGfx: Avoid signed comparison in find_largest_image

I believe the issue was caused by the product of two u16s being promoted
to (signed) int, which can cause unwanted overflow behaviour when
comparing to size_t. Casting each term to size_t before the
multiplication makes the comparison unsigned.
This commit is contained in:
Leonardo Duarte 2022-04-13 22:42:06 -03:00 committed by Idan Horowitz
parent d3bc3da873
commit 62baf25f0b

View file

@ -123,7 +123,7 @@ static size_t find_largest_image(ICOLoadingContext const& context)
size_t index = 0;
size_t largest_index = 0;
for (auto const& desc : context.images) {
if (desc.width * desc.height > max_area) {
if (static_cast<size_t>(desc.width) * static_cast<size_t>(desc.height) > max_area) {
max_area = desc.width * desc.height;
largest_index = index;
}