Skip to content

Commit adbc4f7

Browse files
alanzhao1Chromium LUCI CQ
authored andcommitted
Silence upcoming -Wunsafe-buffer-usage warnings
An upcoming Clang change (llvm/llvm-project#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: [email protected] <[email protected]> Reviewed-by: Nico Weber <[email protected]> Commit-Queue: Nico Weber <[email protected]> Owners-Override: Nico Weber <[email protected]> Cr-Commit-Position: refs/heads/main@{#1380096}
1 parent 6ec51fa commit adbc4f7

File tree

18 files changed

+72
-27
lines changed

18 files changed

+72
-27
lines changed

cc/paint/path_effect.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright 2024 The Chromium Authors
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4+
#ifdef UNSAFE_BUFFERS_BUILD
5+
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
6+
#pragma allow_unsafe_buffers
7+
#endif
48

59
#include "cc/paint/path_effect.h"
610

chrome/browser/sync_file_system/drive_backend/sync_task_manager_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class BlockerUpdateTestHelper : public SyncTask {
230230
Log* log)
231231
: name_(name),
232232
app_id_(app_id),
233-
paths_(paths.begin(), paths.end()),
233+
paths_(base::from_range, paths),
234234
log_(log) {}
235235

236236
BlockerUpdateTestHelper(const BlockerUpdateTestHelper&) = delete;

chrome/updater/device_management/dm_policy_builder_for_testing.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#ifdef UNSAFE_BUFFERS_BUILD
6+
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
7+
#pragma allow_unsafe_buffers
8+
#endif
9+
510
#include "chrome/updater/device_management/dm_policy_builder_for_testing.h"
611

712
#include <stdint.h>

content/browser/media/midi_host_unittest.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <stddef.h>
88
#include <stdint.h>
99

10+
#include "base/containers/to_vector.h"
1011
#include "base/memory/weak_ptr.h"
1112
#include "base/run_loop.h"
1213
#include "base/strings/stringprintf.h"
@@ -133,7 +134,7 @@ class MidiSessionClientForTesting : public midi::mojom::MidiSessionClient {
133134

134135
class MidiHostTest : public testing::Test {
135136
public:
136-
MidiHostTest() : data_(kNoteOn, kNoteOn + std::size(kNoteOn)), port_id_(0) {
137+
MidiHostTest() : data_(base::ToVector(kNoteOn)), port_id_(0) {
137138
browser_context_ = std::make_unique<TestBrowserContext>();
138139
rph_ = std::make_unique<MockRenderProcessHost>(browser_context_.get());
139140
std::unique_ptr<FakeMidiManagerFactory> factory =

content/browser/renderer_host/frame_tree.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "base/memory/safe_ref.h"
2121
#include "base/not_fatal_until.h"
2222
#include "base/ranges/algorithm.h"
23+
#include "base/ranges/from_range.h"
2324
#include "base/trace_event/optional_trace_event.h"
2425
#include "base/trace_event/typed_macros.h"
2526
#include "base/unguessable_token.h"
@@ -148,7 +149,7 @@ FrameTree::NodeIterator::NodeIterator(
148149
should_descend_into_inner_trees_(should_descend_into_inner_trees),
149150
include_delegate_nodes_for_inner_frame_trees_(
150151
include_delegate_nodes_for_inner_frame_trees),
151-
queue_(starting_nodes.begin(), starting_nodes.end()) {
152+
queue_(base::from_range, starting_nodes) {
152153
// If `include_delegate_nodes_for_inner_frame_trees_` is true then
153154
// `should_descend_into_inner_trees_` must be true.
154155
DCHECK(!include_delegate_nodes_for_inner_frame_trees_ ||

content/browser/service_worker/service_worker_new_script_loader.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#ifdef UNSAFE_BUFFERS_BUILD
6+
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
7+
#pragma allow_unsafe_buffers
8+
#endif
9+
510
#include "content/browser/service_worker/service_worker_new_script_loader.h"
611

712
#include <memory>

content/browser/service_worker/service_worker_single_script_update_checker.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#ifdef UNSAFE_BUFFERS_BUILD
6+
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
7+
#pragma allow_unsafe_buffers
8+
#endif
9+
510
#include "content/browser/service_worker/service_worker_single_script_update_checker.h"
611

712
#include <utility>

device/gamepad/dualshock4_controller_unittest.cc

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <memory>
88

9+
#include "base/containers/to_vector.h"
910
#include "base/functional/bind.h"
1011
#include "base/memory/raw_ptr.h"
1112
#include "base/memory/weak_ptr.h"
@@ -110,16 +111,10 @@ class FakeHidWriter : public HidWriter {
110111
class Dualshock4ControllerTest : public testing::Test {
111112
public:
112113
Dualshock4ControllerTest()
113-
: usb_start_vibration_report_(kUsbStartVibration,
114-
kUsbStartVibration + kUsbReportLength),
115-
usb_stop_vibration_report_(kUsbStopVibration,
116-
kUsbStopVibration + kUsbReportLength),
117-
bluetooth_start_vibration_report_(
118-
kBtStartVibration,
119-
kBtStartVibration + kBluetoothReportLength),
120-
bluetooth_stop_vibration_report_(
121-
kBtStopVibration,
122-
kBtStopVibration + kBluetoothReportLength),
114+
: usb_start_vibration_report_(base::ToVector(kUsbStartVibration)),
115+
usb_stop_vibration_report_(base::ToVector(kUsbStopVibration)),
116+
bluetooth_start_vibration_report_(base::ToVector(kBtStartVibration)),
117+
bluetooth_stop_vibration_report_(base::ToVector(kBtStopVibration)),
123118
callback_count_(0),
124119
callback_result_(
125120
mojom::GamepadHapticsResult::GamepadHapticsResultError) {

device/gamepad/hid_haptic_gamepad_unittest.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <memory>
88

9+
#include "base/containers/to_vector.h"
910
#include "base/functional/bind.h"
1011
#include "base/memory/raw_ptr.h"
1112
#include "base/memory/weak_ptr.h"
@@ -71,10 +72,8 @@ class FakeHidWriter : public HidWriter {
7172
class HidHapticGamepadTest : public testing::Test {
7273
public:
7374
HidHapticGamepadTest()
74-
: start_vibration_output_report_(kStartVibrationData,
75-
kStartVibrationData + kReportLength),
76-
stop_vibration_output_report_(kStopVibrationData,
77-
kStopVibrationData + kReportLength),
75+
: start_vibration_output_report_(base::ToVector(kStartVibrationData)),
76+
stop_vibration_output_report_(base::ToVector(kStopVibrationData)),
7877
first_callback_count_(0),
7978
second_callback_count_(0),
8079
first_callback_result_(

device/gamepad/xbox_hid_controller_unittest.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <memory>
88

9+
#include "base/containers/to_vector.h"
910
#include "base/functional/bind.h"
1011
#include "base/memory/raw_ptr.h"
1112
#include "base/memory/weak_ptr.h"
@@ -77,9 +78,8 @@ class FakeHidWriter : public HidWriter {
7778
class XboxHidControllerTest : public testing::Test {
7879
public:
7980
XboxHidControllerTest()
80-
: start_vibration_report_(kStartVibration,
81-
kStartVibration + kReportLength),
82-
stop_vibration_report_(kStopVibration, kStopVibration + kReportLength),
81+
: start_vibration_report_(base::ToVector(kStartVibration)),
82+
stop_vibration_report_(base::ToVector(kStopVibration)),
8383
callback_count_(0),
8484
callback_result_(
8585
mojom::GamepadHapticsResult::GamepadHapticsResultError) {

extensions/browser/api/system_storage/system_storage_apitest.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#ifdef UNSAFE_BUFFERS_BUILD
6+
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
7+
#pragma allow_unsafe_buffers
8+
#endif
9+
510
#include <stddef.h>
611

712
#include <atomic>

extensions/browser/content_verifier/test_utils.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,15 @@ bool TestContentVerifyJobObserver::ObserverClient::WaitForExpectedJobs() {
202202
}
203203

204204
// MockContentVerifierDelegate ------------------------------------------------
205-
MockContentVerifierDelegate::MockContentVerifierDelegate()
206-
: verifier_key_(
207-
kWebstoreSignaturesPublicKey,
208-
kWebstoreSignaturesPublicKey + kWebstoreSignaturesPublicKeySize) {}
205+
MockContentVerifierDelegate::MockContentVerifierDelegate() {
206+
// SAFETY: Pointer arithmetic is safe because the passed values are global
207+
// constants. base::ToVector(...) cannot be used because
208+
// kWebstoreSignaturesPublicKey is defined in another TU and therefore this TU
209+
// does not know the array size.
210+
verifier_key_ = UNSAFE_BUFFERS(std::vector<uint8_t>(
211+
kWebstoreSignaturesPublicKey,
212+
kWebstoreSignaturesPublicKey + kWebstoreSignaturesPublicKeySize));
213+
}
209214

210215
MockContentVerifierDelegate::~MockContentVerifierDelegate() = default;
211216

media/base/cdm_key_information.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#ifdef UNSAFE_BUFFERS_BUILD
6+
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
7+
#pragma allow_unsafe_buffers
8+
#endif
9+
510
#include "media/base/cdm_key_information.h"
611

712
#include <ostream>

media/cdm/aes_cbc_crypto_unittest.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <optional>
99

1010
#include "base/containers/span.h"
11+
#include "base/containers/to_vector.h"
1112
#include "base/memory/raw_span.h"
1213
#include "crypto/encryptor.h"
1314
#include "crypto/symmetric_key.h"
@@ -66,8 +67,8 @@ class AesCbcCryptoTest : public testing::Test {
6667
key2_(crypto::SymmetricKey::Import(
6768
crypto::SymmetricKey::AES,
6869
std::string(std::begin(kKey2), std::end(kKey2)))),
69-
iv_(std::begin(kIv), std::end(kIv)),
70-
one_block_(std::begin(kOneBlock), std::end(kOneBlock)) {}
70+
iv_(kIv),
71+
one_block_(base::ToVector(kOneBlock)) {}
7172

7273
// Encrypt |original| using AES-CBC encryption with |key| and |iv|.
7374
std::vector<uint8_t> Encrypt(const std::vector<uint8_t>& original,

media/formats/webm/webm_webvtt_parser.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#ifdef UNSAFE_BUFFERS_BUILD
6+
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
7+
#pragma allow_unsafe_buffers
8+
#endif
9+
510
#include "media/formats/webm/webm_webvtt_parser.h"
611

712
namespace media {

net/quic/quic_chromium_client_session_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class QuicChromiumClientSessionTest
121121
default_read_(
122122
std::make_unique<MockRead>(SYNCHRONOUS, ERR_IO_PENDING, 0)),
123123
socket_data_(std::make_unique<SequencedSocketData>(
124-
base::make_span(default_read_.get(), 1u),
124+
base::span_from_ref(*default_read_),
125125
base::span<MockWrite>())),
126126
helper_(&clock_, &random_),
127127
transport_security_state_(std::make_unique<TransportSecurityState>()),

third_party/blink/public/platform/web_vector.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*/
3030

31+
#ifdef UNSAFE_BUFFERS_BUILD
32+
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
33+
#pragma allow_unsafe_buffers
34+
#endif
35+
3136
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_VECTOR_H_
3237
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_VECTOR_H_
3338

ui/gfx/vector_icon_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright 2015 The Chromium Authors
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4+
#ifdef UNSAFE_BUFFERS_BUILD
5+
// TODO(crbug.com/377326291): Remove this and convert code to safer constructs.
6+
#pragma allow_unsafe_buffers
7+
#endif
48

59
#ifndef UI_GFX_VECTOR_ICON_TYPES_H_
610
#define UI_GFX_VECTOR_ICON_TYPES_H_

0 commit comments

Comments
 (0)