From 87f5d788c0210a975200067beea7d4cdc6aa8fc0 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 22:18:31 -0500 Subject: [PATCH] fix: -Wunsafe-buffer-usage warning in V8Serializer::Serialize() (#43674) Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- shell/common/v8_value_serializer.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/shell/common/v8_value_serializer.cc b/shell/common/v8_value_serializer.cc index 96251a149ad3..915a6779ba1e 100644 --- a/shell/common/v8_value_serializer.cc +++ b/shell/common/v8_value_serializer.cc @@ -49,10 +49,12 @@ class V8Serializer : public v8::ValueSerializer::Delegate { } DCHECK(wrote_value); - std::pair buffer = serializer_.Release(); - DCHECK_EQ(buffer.first, data_.data()); - out->encoded_message = base::make_span(buffer.first, buffer.second); + const auto [data_bytes, data_len] = serializer_.Release(); + DCHECK_EQ(std::data(data_), data_bytes); + DCHECK_GE(std::size(data_), data_len); + data_.resize(data_len); out->owned_encoded_message = std::move(data_); + out->encoded_message = out->owned_encoded_message; out->sender_agent_cluster_id = blink::WebMessagePort::GetEmbedderAgentClusterID();