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
commit 62baf25f0b
Notes: sideshowbarker 2024-07-17 11:39:39 +09:00

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;
}