fix: -Wunsafe-buffer-usage warnings in Clipboard::WriteBuffer() (#43812)
* fix: -Wunsafe-buffer-usage warnings in Clipboard::WriteBuffer() Co-authored-by: Charles Kerr <charles@charleskerr.com> * chore: add a DCHECK to confirm the BigBuffer is full Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
568314240e
commit
334a3fbea6
1 changed files with 9 additions and 5 deletions
|
@ -111,12 +111,16 @@ void Clipboard::WriteBuffer(const std::string& format,
|
||||||
return;
|
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));
|
ui::ScopedClipboardWriter writer(GetClipboardBuffer(args));
|
||||||
base::span<const uint8_t> payload_span(
|
writer.WriteUnsafeRawData(base::UTF8ToUTF16(format), std::move(big_buffer));
|
||||||
reinterpret_cast<const uint8_t*>(node::Buffer::Data(buffer)),
|
|
||||||
node::Buffer::Length(buffer));
|
|
||||||
writer.WriteUnsafeRawData(base::UTF8ToUTF16(format),
|
|
||||||
mojo_base::BigBuffer(payload_span));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clipboard::Write(const gin_helper::Dictionary& data,
|
void Clipboard::Write(const gin_helper::Dictionary& data,
|
||||||
|
|
Loading…
Reference in a new issue