fix: -Wunsafe-buffer-usage warnings in TaskbarHost::SetThumbarButtons() (#44259)
* fix: -Wunsafe-buffer-usage warnings in TaskbarHost::SetThumbarButtons() Co-authored-by: Charles Kerr <charles@charleskerr.com> * fixup! fix: -Wunsafe-buffer-usage warning in ChunkedDataPipeReadableStream (#44211) Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
36b7cf341e
commit
354d6155d8
2 changed files with 12 additions and 10 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include "shell/browser/ui/win/taskbar_host.h"
|
#include "shell/browser/ui/win/taskbar_host.h"
|
||||||
|
|
||||||
#include <objbase.h>
|
#include <objbase.h>
|
||||||
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
|
@ -25,10 +26,10 @@ namespace {
|
||||||
// From MSDN:
|
// From MSDN:
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd378460(v=vs.85).aspx#thumbbars
|
// 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.
|
// 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.
|
// The base id of Thumbar button.
|
||||||
const int kButtonIdBase = 40001;
|
constexpr int kButtonIdBase = 40001;
|
||||||
|
|
||||||
bool GetThumbarButtonFlags(const std::vector<std::string>& flags,
|
bool GetThumbarButtonFlags(const std::vector<std::string>& flags,
|
||||||
THUMBBUTTONFLAGS* out) {
|
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,
|
// 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
|
// so we have to claim kMaxButtonsCount buttons initially in case users add
|
||||||
// more buttons later.
|
// more buttons later.
|
||||||
base::win::ScopedHICON icons[kMaxButtonsCount] = {};
|
auto icons = std::array<base::win::ScopedHICON, kMaxButtonsCount>{};
|
||||||
THUMBBUTTON thumb_buttons[kMaxButtonsCount] = {};
|
auto thumb_buttons = std::array<THUMBBUTTON, kMaxButtonsCount>{};
|
||||||
|
|
||||||
for (size_t i = 0; i < kMaxButtonsCount; ++i) {
|
for (size_t i = 0U; i < kMaxButtonsCount; ++i) {
|
||||||
THUMBBUTTON& thumb_button = thumb_buttons[i];
|
THUMBBUTTON& thumb_button = thumb_buttons[i];
|
||||||
|
|
||||||
// Set ID.
|
// Set ID.
|
||||||
|
@ -118,10 +119,11 @@ bool TaskbarHost::SetThumbarButtons(HWND window,
|
||||||
// Finally add them to taskbar.
|
// Finally add them to taskbar.
|
||||||
HRESULT r;
|
HRESULT r;
|
||||||
if (thumbar_buttons_added_) {
|
if (thumbar_buttons_added_) {
|
||||||
r = taskbar_->ThumbBarUpdateButtons(window, kMaxButtonsCount,
|
r = taskbar_->ThumbBarUpdateButtons(window, thumb_buttons.size(),
|
||||||
thumb_buttons);
|
thumb_buttons.data());
|
||||||
} else {
|
} else {
|
||||||
r = taskbar_->ThumbBarAddButtons(window, kMaxButtonsCount, thumb_buttons);
|
r = taskbar_->ThumbBarAddButtons(window, thumb_buttons.size(),
|
||||||
|
thumb_buttons.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
thumbar_buttons_added_ = true;
|
thumbar_buttons_added_ = true;
|
||||||
|
|
|
@ -252,8 +252,8 @@ namespace util {
|
||||||
* |v8::ArrayBufferView::ByteLength()|.
|
* |v8::ArrayBufferView::ByteLength()|.
|
||||||
*/
|
*/
|
||||||
base::span<uint8_t> as_byte_span(v8::Local<v8::ArrayBufferView> val) {
|
base::span<uint8_t> as_byte_span(v8::Local<v8::ArrayBufferView> val) {
|
||||||
uint8_t* data =
|
uint8_t* data = UNSAFE_BUFFERS(static_cast<uint8_t*>(val->Buffer()->Data()) +
|
||||||
static_cast<uint8_t*>(val->Buffer()->Data()) + val->ByteOffset();
|
val->ByteOffset());
|
||||||
const size_t size = val->ByteLength();
|
const size_t size = val->ByteLength();
|
||||||
return UNSAFE_BUFFERS(base::span{data, size});
|
return UNSAFE_BUFFERS(base::span{data, size});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue