Index: remoting/base/compound_buffer.cc |
diff --git a/remoting/base/compound_buffer.cc b/remoting/base/compound_buffer.cc |
index 79b4d32818b9f65127ab93bcc59768c084f9640f..3c599d363b9360ad35f0e0d768b36fae3ec64c07 100644 |
--- a/remoting/base/compound_buffer.cc |
+++ b/remoting/base/compound_buffer.cc |
@@ -144,12 +144,12 @@ net::IOBufferWithSize* CompoundBuffer::ToIOBufferWithSize() const { |
} |
void CompoundBuffer::CopyTo(char* data, int size) const { |
- char* pos = data; |
+ int pos = 0; |
for (DataChunkList::const_iterator it = chunks_.begin(); |
- it != chunks_.end(); ++it) { |
- CHECK_LE(pos + it->size, data + size); |
- memcpy(pos, it->start, it->size); |
- pos += it->size; |
+ it != chunks_.end() && pos < size; ++it) { |
+ int bytes_to_copy = std::min(size - pos, it->size); |
+ memcpy(data + pos, it->start, bytes_to_copy); |
+ pos += bytes_to_copy; |
} |
} |