fix: -Wunsafe-buffer-usage warnings in Clipboard::WriteBuffer() (#43795)

* fix: -Wunsafe-buffer-usage warnings in Clipboard::WriteBuffer()

* chore: add a DCHECK to confirm the BigBuffer is full
This commit is contained in:
Charles Kerr 2024-09-19 23:10:35 -05:00 committed by GitHub
parent 6aa6bada79
commit 53e89b565d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -111,12 +111,16 @@ void Clipboard::WriteBuffer(const std::string& format,
return;
}
CHECK(buffer->IsArrayBufferView());
v8::Local<v8::ArrayBufferView> buffer_view = buffer.As<v8::ArrayBufferView>();
const size_t n_bytes = buffer_view->ByteLength();
mojo_base::BigBuffer big_buffer{n_bytes};
[[maybe_unused]] const size_t n_got =
buffer_view->CopyContents(big_buffer.data(), n_bytes);
DCHECK_EQ(n_got, n_bytes);
ui::ScopedClipboardWriter writer(GetClipboardBuffer(args));
base::span<const uint8_t> payload_span(
reinterpret_cast<const uint8_t*>(node::Buffer::Data(buffer)),
node::Buffer::Length(buffer));
writer.WriteUnsafeRawData(base::UTF8ToUTF16(format),
mojo_base::BigBuffer(payload_span));
writer.WriteUnsafeRawData(base::UTF8ToUTF16(format), std::move(big_buffer));
}
void Clipboard::Write(const gin_helper::Dictionary& data,