OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/pickle.h" | 5 #include "base/pickle.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include <algorithm> // for max() | 9 #include <algorithm> // for max() |
10 | 10 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 WriteBytesCommon(data, length); | 351 WriteBytesCommon(data, length); |
352 } | 352 } |
353 | 353 |
354 template void Pickle::WriteBytesStatic<2>(const void* data); | 354 template void Pickle::WriteBytesStatic<2>(const void* data); |
355 template void Pickle::WriteBytesStatic<4>(const void* data); | 355 template void Pickle::WriteBytesStatic<4>(const void* data); |
356 template void Pickle::WriteBytesStatic<8>(const void* data); | 356 template void Pickle::WriteBytesStatic<8>(const void* data); |
357 | 357 |
358 inline void Pickle::WriteBytesCommon(const void* data, size_t length) { | 358 inline void Pickle::WriteBytesCommon(const void* data, size_t length) { |
359 DCHECK_NE(kCapacityReadOnly, capacity_after_header_) | 359 DCHECK_NE(kCapacityReadOnly, capacity_after_header_) |
360 << "oops: pickle is readonly"; | 360 << "oops: pickle is readonly"; |
| 361 MSAN_CHECK_MEM_IS_INITIALIZED(data, length); |
361 size_t data_len = AlignInt(length, sizeof(uint32)); | 362 size_t data_len = AlignInt(length, sizeof(uint32)); |
362 DCHECK_GE(data_len, length); | 363 DCHECK_GE(data_len, length); |
363 #ifdef ARCH_CPU_64_BITS | 364 #ifdef ARCH_CPU_64_BITS |
364 DCHECK_LE(data_len, kuint32max); | 365 DCHECK_LE(data_len, kuint32max); |
365 #endif | 366 #endif |
366 DCHECK_LE(write_offset_, kuint32max - data_len); | 367 DCHECK_LE(write_offset_, kuint32max - data_len); |
367 size_t new_size = write_offset_ + data_len; | 368 size_t new_size = write_offset_ + data_len; |
368 if (new_size > capacity_after_header_) { | 369 if (new_size > capacity_after_header_) { |
369 Resize(std::max(capacity_after_header_ * 2, new_size)); | 370 Resize(std::max(capacity_after_header_ * 2, new_size)); |
370 } | 371 } |
371 | 372 |
372 char* write = mutable_payload() + write_offset_; | 373 char* write = mutable_payload() + write_offset_; |
373 memcpy(write, data, length); | 374 memcpy(write, data, length); |
374 memset(write + length, 0, data_len - length); | 375 memset(write + length, 0, data_len - length); |
375 header_->payload_size = static_cast<uint32>(new_size); | 376 header_->payload_size = static_cast<uint32>(new_size); |
376 write_offset_ = new_size; | 377 write_offset_ = new_size; |
377 } | 378 } |
OLD | NEW |