fix: -Wunsafe-buffer-usage warning in WriteAsciiChunk() (#44169)
* fix: -Wunsafe-buffer-usage warning in WriteAsciiChunk() Co-authored-by: Charles Kerr <charles@charleskerr.com> * chore: add // SAFETY comment to explain UNSAFE_BUFFERS() use 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
5244fcecd3
commit
c9474ef5da
1 changed files with 8 additions and 2 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "shell/common/heap_snapshot.h"
|
#include "shell/common/heap_snapshot.h"
|
||||||
|
|
||||||
|
#include "base/containers/span.h"
|
||||||
#include "base/files/file.h"
|
#include "base/files/file.h"
|
||||||
#include "base/memory/raw_ptr.h"
|
#include "base/memory/raw_ptr.h"
|
||||||
#include "v8/include/v8-profiler.h"
|
#include "v8/include/v8-profiler.h"
|
||||||
|
@ -24,8 +25,13 @@ class HeapSnapshotOutputStream : public v8::OutputStream {
|
||||||
void EndOfStream() override { is_complete_ = true; }
|
void EndOfStream() override { is_complete_ = true; }
|
||||||
|
|
||||||
v8::OutputStream::WriteResult WriteAsciiChunk(char* data, int size) override {
|
v8::OutputStream::WriteResult WriteAsciiChunk(char* data, int size) override {
|
||||||
auto bytes_written = file_->WriteAtCurrentPos(data, size);
|
const uint8_t* udata = reinterpret_cast<const uint8_t*>(data);
|
||||||
return bytes_written == size ? kContinue : kAbort;
|
const size_t usize = static_cast<size_t>(std::max(0, size));
|
||||||
|
// SAFETY: since WriteAsciiChunk() only gives us data + size, our
|
||||||
|
// UNSAFE_BUFFERS macro call is unavoidable here. It can be removed
|
||||||
|
// if/when v8 changes WriteAsciiChunk() to pass a v8::MemorySpan.
|
||||||
|
const auto data_span = UNSAFE_BUFFERS(base::span(udata, usize));
|
||||||
|
return file_->WriteAtCurrentPosAndCheck(data_span) ? kContinue : kAbort;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue