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 #include <limits> | 10 #include <limits> |
11 | 11 |
12 #include "base/bits.h" | 12 #include "base/bits.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "build/build_config.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 | 17 |
17 // static | 18 // static |
18 const int Pickle::kPayloadUnit = 64; | 19 const int Pickle::kPayloadUnit = 64; |
19 | 20 |
20 static const size_t kCapacityReadOnly = static_cast<size_t>(-1); | 21 static const size_t kCapacityReadOnly = static_cast<size_t>(-1); |
21 | 22 |
22 PickleIterator::PickleIterator(const Pickle& pickle) | 23 PickleIterator::PickleIterator(const Pickle& pickle) |
23 : payload_(pickle.payload()), | 24 : payload_(pickle.payload()), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 return NULL; | 65 return NULL; |
65 } | 66 } |
66 const char* current_read_ptr = payload_ + read_index_; | 67 const char* current_read_ptr = payload_ + read_index_; |
67 Advance(num_bytes); | 68 Advance(num_bytes); |
68 return current_read_ptr; | 69 return current_read_ptr; |
69 } | 70 } |
70 | 71 |
71 inline const char* PickleIterator::GetReadPointerAndAdvance( | 72 inline const char* PickleIterator::GetReadPointerAndAdvance( |
72 int num_elements, | 73 int num_elements, |
73 size_t size_element) { | 74 size_t size_element) { |
74 // Check for int32 overflow. | 75 // Check for int32_t overflow. |
75 int64_t num_bytes = static_cast<int64_t>(num_elements) * size_element; | 76 int64_t num_bytes = static_cast<int64_t>(num_elements) * size_element; |
76 int num_bytes32 = static_cast<int>(num_bytes); | 77 int num_bytes32 = static_cast<int>(num_bytes); |
77 if (num_bytes != static_cast<int64_t>(num_bytes32)) | 78 if (num_bytes != static_cast<int64_t>(num_bytes32)) |
78 return NULL; | 79 return NULL; |
79 return GetReadPointerAndAdvance(num_bytes32); | 80 return GetReadPointerAndAdvance(num_bytes32); |
80 } | 81 } |
81 | 82 |
82 bool PickleIterator::ReadBool(bool* result) { | 83 bool PickleIterator::ReadBool(bool* result) { |
83 return ReadBuiltinType(result); | 84 return ReadBuiltinType(result); |
84 } | 85 } |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 | 419 |
419 inline void Pickle::WriteBytesCommon(const void* data, size_t length) { | 420 inline void Pickle::WriteBytesCommon(const void* data, size_t length) { |
420 DCHECK_NE(kCapacityReadOnly, capacity_after_header_) | 421 DCHECK_NE(kCapacityReadOnly, capacity_after_header_) |
421 << "oops: pickle is readonly"; | 422 << "oops: pickle is readonly"; |
422 MSAN_CHECK_MEM_IS_INITIALIZED(data, length); | 423 MSAN_CHECK_MEM_IS_INITIALIZED(data, length); |
423 void* write = ClaimUninitializedBytesInternal(length); | 424 void* write = ClaimUninitializedBytesInternal(length); |
424 memcpy(write, data, length); | 425 memcpy(write, data, length); |
425 } | 426 } |
426 | 427 |
427 } // namespace base | 428 } // namespace base |
OLD | NEW |