0

[Code Health] Replace raw pointer Buffer::data_ with raw_ptr

Bug: 346694189
Change-Id: I67f9f686d206e52916e7f674b21837043d09545f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6019877
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Garrett Beaty <gbeaty@google.com>
Cr-Commit-Position: refs/heads/main@{#1401542}
This commit is contained in:
Garrett Beaty
2025-01-02 12:05:04 -08:00
committed by Chromium LUCI CQ
parent 1b641f8b2c
commit e783032573
2 changed files with 16 additions and 6 deletions
mojo/public/cpp/bindings/lib

@ -73,7 +73,7 @@ size_t Buffer::Allocate(size_t num_bytes) {
uint32_t new_size;
MojoResult rv = MojoAppendMessageData(
message_.value(), static_cast<uint32_t>(additional_bytes), nullptr, 0,
nullptr, &data_, &new_size);
nullptr, &data_.AsEphemeralRawAddr(), &new_size);
DCHECK_EQ(MOJO_RESULT_OK, rv);
message_payload_size_ = new_cursor;
size_ = new_size;
@ -100,7 +100,8 @@ bool Buffer::AttachHandles(std::vector<ScopedHandle>* handles) {
uint32_t new_size = 0;
MojoResult rv = MojoAppendMessageData(
message_.value(), 0, reinterpret_cast<MojoHandle*>(handles->data()),
static_cast<uint32_t>(handles->size()), nullptr, &data_, &new_size);
static_cast<uint32_t>(handles->size()), nullptr,
&data_.AsEphemeralRawAddr(), &new_size);
if (rv != MOJO_RESULT_OK)
return false;

@ -16,7 +16,7 @@
#include <vector>
#include "base/component_export.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/memory/raw_ptr.h"
#include "mojo/public/cpp/system/handle.h"
#include "mojo/public/cpp/system/message.h"
@ -124,9 +124,18 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) Buffer {
// The storage location and capacity currently backing |message_|. Owned by
// the message object internally, not by this Buffer.
// This field is not a raw_ptr<> because it was filtered by the rewriter for:
// #union, #addr-of
RAW_PTR_EXCLUSION void* data_ = nullptr;
// Dangling when running chromedriver_unittests on win-rel (this is not an
// exhaustive list of failures, just ones that provided an easy to view
// backtrace):
// FetchUrlTest.ConnectionClose
// FetchUrlTest.Http200
// FetchUrlTest.HttpNon200
// FetchUrlTest.NoServer
// TestHttpServerTest.ResourceNotFound
// TestHttpServerTest.SetDataForPath
// TestHttpServerTest.Start
// TODO: crbug.com/387315749 - Resolving dangling pointer
raw_ptr<void, DanglingUntriaged> data_ = nullptr;
size_t size_ = 0;
// The current write offset into |data_| if this Buffer is being used for