fix: -Wunsafe-buffer-usage warning in didRegisterForRemoteNotificationsWithDeviceToken (#44381)

* chore: move as_byte_span() to new shell/common/mac_util.h

this way it can be used by multiple mm files

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* fix: -Wunsafe-buffer-usage warnings in UNNotificationResponseToNSDictionary

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use base::HexEncode() instead of rolling our own

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* fixup! chore: move as_byte_span() to new shell/common/mac_util.h

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* fixup! chore: move as_byte_span() to new shell/common/mac_util.h

fix: move mac_util to the right place in filenames.gni

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:
trop[bot] 2024-10-23 20:44:47 -05:00 committed by GitHub
parent 3b3f72e974
commit 964c1a1df8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 49 additions and 25 deletions

20
shell/common/mac_util.mm Normal file
View file

@ -0,0 +1,20 @@
// Copyright (c) 2024 Microsoft, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
#include "base/containers/span.h"
namespace electron::util {
base::span<const uint8_t> as_byte_span(NSData* data) {
// SAFETY: There is no NSData API that passes the UNSAFE_BUFFER_USAGE
// test, so let's isolate the unsafe API use into this function. Instead of
// calling '[data bytes]' and '[data length]' directly, the rest of our
// code should prefer to use spans returned by this function.
return UNSAFE_BUFFERS(base::span{
reinterpret_cast<const uint8_t*>([data bytes]), [data length]});
}
} // namespace electron::util