Browse Source

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.
Leonardo Duarte 3 years ago
parent
commit
62baf25f0b
1 changed files with 1 additions and 1 deletions
  1. 1 1
      Userland/Libraries/LibGfx/ICOLoader.cpp

+ 1 - 1
Userland/Libraries/LibGfx/ICOLoader.cpp

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