Index: webrtc/base/copyonwritebuffer.h |
diff --git a/webrtc/base/copyonwritebuffer.h b/webrtc/base/copyonwritebuffer.h |
index 17f2710f3ecbd404646268d4af9a003d7c2e5465..9e9728ee391073e478793f0c2fc504f4ab852d14 100644 |
--- a/webrtc/base/copyonwritebuffer.h |
+++ b/webrtc/base/copyonwritebuffer.h |
@@ -42,7 +42,9 @@ class CopyOnWriteBuffer { |
template <typename T, typename internal::ByteType<T>::t = 0> |
CopyOnWriteBuffer(const T* data, size_t size, size_t capacity) |
: CopyOnWriteBuffer(size, capacity) { |
- std::memcpy(buffer_->data(), data, size); |
+ if (buffer_) { |
+ std::memcpy(buffer_->data(), data, size); |
+ } |
} |
// Construct a buffer from the contents of an array. |
@@ -129,7 +131,8 @@ class CopyOnWriteBuffer { |
void SetData(const T* data, size_t size) { |
RTC_DCHECK(IsConsistent()); |
if (!buffer_ || !buffer_->HasOneRef()) { |
- buffer_ = new RefCountedObject<Buffer>(data, size, size); |
+ buffer_ = size > 0 ? new RefCountedObject<Buffer>(data, size) |
+ : nullptr; |
} else { |
buffer_->SetData(data, size); |
} |