浏览代码

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 年之前
父节点
当前提交
62baf25f0b
共有 1 个文件被更改,包括 1 次插入1 次删除
  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;
         }