0

Silence upcoming -Wunsafe-buffer-usage warnings

An upcoming Clang change
(https://github.com/llvm/llvm-project/pull/91991) makes
-Wunsafe-buffer-usage warn on member initializers and member initializer
list, so this patch silences those warnings.

Bug: 377326291
Change-Id: I74206f5675f64f4f754793cff2bdb388ef8965cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6002984
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Owners-Override: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1380096}
This commit is contained in:
Alan Zhao
2024-11-08 01:59:36 +00:00
committed by Chromium LUCI CQ
parent 6ec51fa450
commit adbc4f7ffd
18 changed files with 72 additions and 27 deletions

@ -1,6 +1,10 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "cc/paint/path_effect.h"

@ -230,7 +230,7 @@ class BlockerUpdateTestHelper : public SyncTask {
Log* log)
: name_(name),
app_id_(app_id),
paths_(paths.begin(), paths.end()),
paths_(base::from_range, paths),
log_(log) {}
BlockerUpdateTestHelper(const BlockerUpdateTestHelper&) = delete;

@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "chrome/updater/device_management/dm_policy_builder_for_testing.h"
#include <stdint.h>

@ -7,6 +7,7 @@
#include <stddef.h>
#include <stdint.h>
#include "base/containers/to_vector.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
@ -133,7 +134,7 @@ class MidiSessionClientForTesting : public midi::mojom::MidiSessionClient {
class MidiHostTest : public testing::Test {
public:
MidiHostTest() : data_(kNoteOn, kNoteOn + std::size(kNoteOn)), port_id_(0) {
MidiHostTest() : data_(base::ToVector(kNoteOn)), port_id_(0) {
browser_context_ = std::make_unique<TestBrowserContext>();
rph_ = std::make_unique<MockRenderProcessHost>(browser_context_.get());
std::unique_ptr<FakeMidiManagerFactory> factory =

@ -20,6 +20,7 @@
#include "base/memory/safe_ref.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.h"
#include "base/ranges/from_range.h"
#include "base/trace_event/optional_trace_event.h"
#include "base/trace_event/typed_macros.h"
#include "base/unguessable_token.h"
@ -148,7 +149,7 @@ FrameTree::NodeIterator::NodeIterator(
should_descend_into_inner_trees_(should_descend_into_inner_trees),
include_delegate_nodes_for_inner_frame_trees_(
include_delegate_nodes_for_inner_frame_trees),
queue_(starting_nodes.begin(), starting_nodes.end()) {
queue_(base::from_range, starting_nodes) {
// If `include_delegate_nodes_for_inner_frame_trees_` is true then
// `should_descend_into_inner_trees_` must be true.
DCHECK(!include_delegate_nodes_for_inner_frame_trees_ ||

@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "content/browser/service_worker/service_worker_new_script_loader.h"
#include <memory>

@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "content/browser/service_worker/service_worker_single_script_update_checker.h"
#include <utility>

@ -6,6 +6,7 @@
#include <memory>
#include "base/containers/to_vector.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
@ -110,16 +111,10 @@ class FakeHidWriter : public HidWriter {
class Dualshock4ControllerTest : public testing::Test {
public:
Dualshock4ControllerTest()
: usb_start_vibration_report_(kUsbStartVibration,
kUsbStartVibration + kUsbReportLength),
usb_stop_vibration_report_(kUsbStopVibration,
kUsbStopVibration + kUsbReportLength),
bluetooth_start_vibration_report_(
kBtStartVibration,
kBtStartVibration + kBluetoothReportLength),
bluetooth_stop_vibration_report_(
kBtStopVibration,
kBtStopVibration + kBluetoothReportLength),
: usb_start_vibration_report_(base::ToVector(kUsbStartVibration)),
usb_stop_vibration_report_(base::ToVector(kUsbStopVibration)),
bluetooth_start_vibration_report_(base::ToVector(kBtStartVibration)),
bluetooth_stop_vibration_report_(base::ToVector(kBtStopVibration)),
callback_count_(0),
callback_result_(
mojom::GamepadHapticsResult::GamepadHapticsResultError) {

@ -6,6 +6,7 @@
#include <memory>
#include "base/containers/to_vector.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
@ -71,10 +72,8 @@ class FakeHidWriter : public HidWriter {
class HidHapticGamepadTest : public testing::Test {
public:
HidHapticGamepadTest()
: start_vibration_output_report_(kStartVibrationData,
kStartVibrationData + kReportLength),
stop_vibration_output_report_(kStopVibrationData,
kStopVibrationData + kReportLength),
: start_vibration_output_report_(base::ToVector(kStartVibrationData)),
stop_vibration_output_report_(base::ToVector(kStopVibrationData)),
first_callback_count_(0),
second_callback_count_(0),
first_callback_result_(

@ -6,6 +6,7 @@
#include <memory>
#include "base/containers/to_vector.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
@ -77,9 +78,8 @@ class FakeHidWriter : public HidWriter {
class XboxHidControllerTest : public testing::Test {
public:
XboxHidControllerTest()
: start_vibration_report_(kStartVibration,
kStartVibration + kReportLength),
stop_vibration_report_(kStopVibration, kStopVibration + kReportLength),
: start_vibration_report_(base::ToVector(kStartVibration)),
stop_vibration_report_(base::ToVector(kStopVibration)),
callback_count_(0),
callback_result_(
mojom::GamepadHapticsResult::GamepadHapticsResultError) {

@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include <stddef.h>
#include <atomic>

@ -202,10 +202,15 @@ bool TestContentVerifyJobObserver::ObserverClient::WaitForExpectedJobs() {
}
// MockContentVerifierDelegate ------------------------------------------------
MockContentVerifierDelegate::MockContentVerifierDelegate()
: verifier_key_(
kWebstoreSignaturesPublicKey,
kWebstoreSignaturesPublicKey + kWebstoreSignaturesPublicKeySize) {}
MockContentVerifierDelegate::MockContentVerifierDelegate() {
// SAFETY: Pointer arithmetic is safe because the passed values are global
// constants. base::ToVector(...) cannot be used because
// kWebstoreSignaturesPublicKey is defined in another TU and therefore this TU
// does not know the array size.
verifier_key_ = UNSAFE_BUFFERS(std::vector<uint8_t>(
kWebstoreSignaturesPublicKey,
kWebstoreSignaturesPublicKey + kWebstoreSignaturesPublicKeySize));
}
MockContentVerifierDelegate::~MockContentVerifierDelegate() = default;

@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "media/base/cdm_key_information.h"
#include <ostream>

@ -8,6 +8,7 @@
#include <optional>
#include "base/containers/span.h"
#include "base/containers/to_vector.h"
#include "base/memory/raw_span.h"
#include "crypto/encryptor.h"
#include "crypto/symmetric_key.h"
@ -66,8 +67,8 @@ class AesCbcCryptoTest : public testing::Test {
key2_(crypto::SymmetricKey::Import(
crypto::SymmetricKey::AES,
std::string(std::begin(kKey2), std::end(kKey2)))),
iv_(std::begin(kIv), std::end(kIv)),
one_block_(std::begin(kOneBlock), std::end(kOneBlock)) {}
iv_(kIv),
one_block_(base::ToVector(kOneBlock)) {}
// Encrypt |original| using AES-CBC encryption with |key| and |iv|.
std::vector<uint8_t> Encrypt(const std::vector<uint8_t>& original,

@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "media/formats/webm/webm_webvtt_parser.h"
namespace media {

@ -121,7 +121,7 @@ class QuicChromiumClientSessionTest
default_read_(
std::make_unique<MockRead>(SYNCHRONOUS, ERR_IO_PENDING, 0)),
socket_data_(std::make_unique<SequencedSocketData>(
base::make_span(default_read_.get(), 1u),
base::span_from_ref(*default_read_),
base::span<MockWrite>())),
helper_(&clock_, &random_),
transport_security_state_(std::make_unique<TransportSecurityState>()),

@ -28,6 +28,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_VECTOR_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_VECTOR_H_

@ -1,6 +1,10 @@
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#ifndef UI_GFX_VECTOR_ICON_TYPES_H_
#define UI_GFX_VECTOR_ICON_TYPES_H_