Commit 8d368f09 authored by Philip Pfaffe's avatar Philip Pfaffe Committed by Commit Bot

[wasm] ZoneBuffer: Avoid memcpy of Empty Byte Arrays

Trying to write an empty byte array currently invokes undefined behavior
if the byte array is null. That's the case when trying to write an empty
vector for example. Copying zero bytes from nullptr is defined as UB for
memcpy.

Change-Id: I6f7e920c1e19e8b2e3779bbc1c0ad79fc8bd6e98
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2148789
Commit-Queue: Philip Pfaffe <pfaffe@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67168}
parent b7981e3b
......@@ -83,6 +83,7 @@ class ZoneBuffer : public ZoneObject {
void write_f64(double val) { write_u64(bit_cast<uint64_t>(val)); }
void write(const byte* data, size_t size) {
if (size == 0) return;
EnsureSpace(size);
memcpy(pos_, data, size);
pos_ += size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment