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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 99 } |
100 | 100 |
101 bool PickleIterator::ReadInt64(int64* result) { | 101 bool PickleIterator::ReadInt64(int64* result) { |
102 return ReadBuiltinType(result); | 102 return ReadBuiltinType(result); |
103 } | 103 } |
104 | 104 |
105 bool PickleIterator::ReadUInt64(uint64* result) { | 105 bool PickleIterator::ReadUInt64(uint64* result) { |
106 return ReadBuiltinType(result); | 106 return ReadBuiltinType(result); |
107 } | 107 } |
108 | 108 |
| 109 bool PickleIterator::ReadSizeT(size_t* result) { |
| 110 // Always read size_t as a 64-bit value to ensure compatibility between 32-bit |
| 111 // and 64-bit processes. |
| 112 uint64 result_uint64 = 0; |
| 113 bool success = ReadBuiltinType(&result_uint64); |
| 114 *result = static_cast<size_t>(result_uint64); |
| 115 // Fail if the cast above truncates the value. |
| 116 return success && (*result == result_uint64); |
| 117 } |
| 118 |
109 bool PickleIterator::ReadFloat(float* result) { | 119 bool PickleIterator::ReadFloat(float* result) { |
110 // crbug.com/315213 | 120 // crbug.com/315213 |
111 // The source data may not be properly aligned, and unaligned float reads | 121 // The source data may not be properly aligned, and unaligned float reads |
112 // cause SIGBUS on some ARM platforms, so force using memcpy to copy the data | 122 // cause SIGBUS on some ARM platforms, so force using memcpy to copy the data |
113 // into the result. | 123 // into the result. |
114 const char* read_from = GetReadPointerAndAdvance<float>(); | 124 const char* read_from = GetReadPointerAndAdvance<float>(); |
115 if (!read_from) | 125 if (!read_from) |
116 return false; | 126 return false; |
117 memcpy(result, read_from, sizeof(*result)); | 127 memcpy(result, read_from, sizeof(*result)); |
118 return true; | 128 return true; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 if (new_size > capacity_after_header_) { | 363 if (new_size > capacity_after_header_) { |
354 Resize(std::max(capacity_after_header_ * 2, new_size)); | 364 Resize(std::max(capacity_after_header_ * 2, new_size)); |
355 } | 365 } |
356 | 366 |
357 char* write = mutable_payload() + write_offset_; | 367 char* write = mutable_payload() + write_offset_; |
358 memcpy(write, data, length); | 368 memcpy(write, data, length); |
359 memset(write + length, 0, data_len - length); | 369 memset(write + length, 0, data_len - length); |
360 header_->payload_size = static_cast<uint32>(new_size); | 370 header_->payload_size = static_cast<uint32>(new_size); |
361 write_offset_ = new_size; | 371 write_offset_ = new_size; |
362 } | 372 } |
OLD | NEW |