From 354d6155d85f40cf413ceb7710f564e253adc5fc Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:31:35 -0500 Subject: [PATCH] fix: -Wunsafe-buffer-usage warnings in TaskbarHost::SetThumbarButtons() (#44259) * fix: -Wunsafe-buffer-usage warnings in TaskbarHost::SetThumbarButtons() Co-authored-by: Charles Kerr * fixup! fix: -Wunsafe-buffer-usage warning in ChunkedDataPipeReadableStream (#44211) Co-authored-by: Charles Kerr --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- shell/browser/ui/win/taskbar_host.cc | 18 ++++++++++-------- shell/common/v8_util.cc | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/shell/browser/ui/win/taskbar_host.cc b/shell/browser/ui/win/taskbar_host.cc index a4c6e988ffb..568067fa023 100644 --- a/shell/browser/ui/win/taskbar_host.cc +++ b/shell/browser/ui/win/taskbar_host.cc @@ -5,6 +5,7 @@ #include "shell/browser/ui/win/taskbar_host.h" #include +#include #include #include "base/strings/utf_string_conversions.h" @@ -25,10 +26,10 @@ namespace { // From MSDN: // https://msdn.microsoft.com/en-us/library/windows/desktop/dd378460(v=vs.85).aspx#thumbbars // The thumbnail toolbar has a maximum of seven buttons due to the limited room. -const size_t kMaxButtonsCount = 7; +constexpr size_t kMaxButtonsCount = 7U; // The base id of Thumbar button. -const int kButtonIdBase = 40001; +constexpr int kButtonIdBase = 40001; bool GetThumbarButtonFlags(const std::vector& flags, THUMBBUTTONFLAGS* out) { @@ -72,10 +73,10 @@ bool TaskbarHost::SetThumbarButtons(HWND window, // The number of buttons in thumbar can not be changed once it is created, // so we have to claim kMaxButtonsCount buttons initially in case users add // more buttons later. - base::win::ScopedHICON icons[kMaxButtonsCount] = {}; - THUMBBUTTON thumb_buttons[kMaxButtonsCount] = {}; + auto icons = std::array{}; + auto thumb_buttons = std::array{}; - for (size_t i = 0; i < kMaxButtonsCount; ++i) { + for (size_t i = 0U; i < kMaxButtonsCount; ++i) { THUMBBUTTON& thumb_button = thumb_buttons[i]; // Set ID. @@ -118,10 +119,11 @@ bool TaskbarHost::SetThumbarButtons(HWND window, // Finally add them to taskbar. HRESULT r; if (thumbar_buttons_added_) { - r = taskbar_->ThumbBarUpdateButtons(window, kMaxButtonsCount, - thumb_buttons); + r = taskbar_->ThumbBarUpdateButtons(window, thumb_buttons.size(), + thumb_buttons.data()); } else { - r = taskbar_->ThumbBarAddButtons(window, kMaxButtonsCount, thumb_buttons); + r = taskbar_->ThumbBarAddButtons(window, thumb_buttons.size(), + thumb_buttons.data()); } thumbar_buttons_added_ = true; diff --git a/shell/common/v8_util.cc b/shell/common/v8_util.cc index 7ed0f003403..80a9300e7a2 100644 --- a/shell/common/v8_util.cc +++ b/shell/common/v8_util.cc @@ -252,8 +252,8 @@ namespace util { * |v8::ArrayBufferView::ByteLength()|. */ base::span as_byte_span(v8::Local val) { - uint8_t* data = - static_cast(val->Buffer()->Data()) + val->ByteOffset(); + uint8_t* data = UNSAFE_BUFFERS(static_cast(val->Buffer()->Data()) + + val->ByteOffset()); const size_t size = val->ByteLength(); return UNSAFE_BUFFERS(base::span{data, size}); }