Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3402)

Unified Diff: base/pickle.cc

Issue 1524613002: [mojo] Use base::Pickle for Message storage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: happy compiler happy robots Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/pickle.h ('k') | base/pickle_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/pickle.cc
diff --git a/base/pickle.cc b/base/pickle.cc
index 6fcdece39ec2cd4a1b7be947989a22f68725dc1e..678c425e9439b76c24acfab1638b286ada81ed73 100644
--- a/base/pickle.cc
+++ b/base/pickle.cc
@@ -329,6 +329,13 @@ void Pickle::Resize(size_t new_capacity) {
header_ = reinterpret_cast<Header*>(p);
}
+void* Pickle::ClaimBytes(size_t num_bytes) {
+ void* p = ClaimUninitializedBytesInternal(num_bytes);
+ CHECK(p);
+ memset(p, 0, num_bytes);
+ return p;
+}
+
size_t Pickle::GetTotalAllocatedSize() const {
if (capacity_after_header_ == kCapacityReadOnly)
return 0;
@@ -384,10 +391,9 @@ template void Pickle::WriteBytesStatic<2>(const void* data);
template void Pickle::WriteBytesStatic<4>(const void* data);
template void Pickle::WriteBytesStatic<8>(const void* data);
-inline void Pickle::WriteBytesCommon(const void* data, size_t length) {
+inline void* Pickle::ClaimUninitializedBytesInternal(size_t length) {
DCHECK_NE(kCapacityReadOnly, capacity_after_header_)
<< "oops: pickle is readonly";
- MSAN_CHECK_MEM_IS_INITIALIZED(data, length);
size_t data_len = bits::Align(length, sizeof(uint32_t));
DCHECK_GE(data_len, length);
#ifdef ARCH_CPU_64_BITS
@@ -404,10 +410,18 @@ inline void Pickle::WriteBytesCommon(const void* data, size_t length) {
}
char* write = mutable_payload() + write_offset_;
- memcpy(write, data, length);
- memset(write + length, 0, data_len - length);
+ memset(write + length, 0, data_len - length); // Always initialize padding
header_->payload_size = static_cast<uint32_t>(new_size);
write_offset_ = new_size;
+ return write;
+}
+
+inline void Pickle::WriteBytesCommon(const void* data, size_t length) {
+ DCHECK_NE(kCapacityReadOnly, capacity_after_header_)
+ << "oops: pickle is readonly";
+ MSAN_CHECK_MEM_IS_INITIALIZED(data, length);
+ void* write = ClaimUninitializedBytesInternal(length);
+ memcpy(write, data, length);
}
} // namespace base
« no previous file with comments | « base/pickle.h ('k') | base/pickle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698