Repository: electron/electron
File: shell/browser/ui/message_box_win.cc (C++)

Code before:
                                const std::vector<std::wstring>& buttons,
                                int default_id,
                                int cancel_id,
                                bool no_link,
                                const std::u16string& title,
                                const std::u16string& message,
                                const std::u16string& detail,
                                const std::u16string& checkbox_label,
                                bool checkbox_checked,
                                const gfx::ImageSkia& icon,
                                HWND* hwnd) {
  TASKDIALOG_FLAGS flags =
      TDF_SIZE_TO_CONTENT |           // Show all content.
      TDF_ALLOW_DIALOG_CANCELLATION;  // Allow canceling the dialog.

  TASKDIALOGCONFIG config = {0};
  config.cbSize = sizeof(config);
  config.hInstance = GetModuleHandle(nullptr);
  config.dwFlags = flags;

  if (parent) {
    config.hwndParent = parent;
    config.dwFlags |= TDF_POSITION_RELATIVE_TO_WINDOW;
  }

  if (default_id >= 0 && static_cast<size_t>(default_id) < buttons.size()) {
    if (!no_link) {
      auto common = GetCommonID(buttons[default_id]);
      if (common.button != -1) {
        config.nDefaultButton = common.id;
      } else {
        config.nDefaultButton = kIDStart + default_id;
      }
    } else {
      config.nDefaultButton = kIDStart + default_id;
    }
  }

  // TaskDialogIndirect doesn't allow empty name, if we set empty title it
  // will show "electron.exe" in title.
  std::wstring app_name;
  if (title.empty()) {
    app_name = base::UTF8ToWide(Browser::Get()->GetName());
    config.pszWindowTitle = app_name.c_str();
  } else {
    config.pszWindowTitle = base::as_wcstr(title);
  }

  base::win::ScopedGDIObject<HICON> hicon;
  if (!icon.isNull()) {
    hicon = IconUtil::CreateHICONFromSkBitmap(*icon.bitmap());

Review comment (suggestion):
prefer utilities from base/numerics/safe_conversions.h for conversions.

```suggestion
  if (default_id >= 0 && base::checked_cast<size_t>(default_id) < buttons.size()) {
```

Code after:
                                const std::vector<std::wstring>& buttons,
                                int default_id,
                                int cancel_id,
                                bool no_link,
                                const std::u16string& title,
                                const std::u16string& message,
                                const std::u16string& detail,
                                const std::u16string& checkbox_label,
                                bool checkbox_checked,
                                const gfx::ImageSkia& icon,
                                HWND* hwnd) {
  TASKDIALOG_FLAGS flags =
      TDF_SIZE_TO_CONTENT |           // Show all content.
      TDF_ALLOW_DIALOG_CANCELLATION;  // Allow canceling the dialog.

  TASKDIALOGCONFIG config = {0};
  config.cbSize = sizeof(config);
  config.hInstance = GetModuleHandle(nullptr);
  config.dwFlags = flags;

  if (parent) {
    config.hwndParent = parent;
    config.dwFlags |= TDF_POSITION_RELATIVE_TO_WINDOW;
  }

  if (default_id >= 0 &&
      base::checked_cast<size_t>(default_id) < buttons.size()) {
    if (!no_link) {
      auto common = GetCommonID(buttons[default_id]);
      if (common.button != -1) {
        config.nDefaultButton = common.id;
      } else {
        config.nDefaultButton = kIDStart + default_id;
      }
    } else {
      config.nDefaultButton = kIDStart + default_id;
    }
  }

  // TaskDialogIndirect doesn't allow empty name, if we set empty title it
  // will show "electron.exe" in title.
  std::wstring app_name;
  if (title.empty()) {
    app_name = base::UTF8ToWide(Browser::Get()->GetName());
    config.pszWindowTitle = app_name.c_str();
  } else {
    config.pszWindowTitle = base::as_wcstr(title);
  }

  base::win::ScopedGDIObject<HICON> hicon;
  if (!icon.isNull()) {