Chromium Code Reviews| 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); | |
|
Tom Sepez
2014/10/01 19:12:45
I'd be OK with this so long as we did a check that
Peter Kasting
2014/10/01 19:42:08
Sure. Changed static_cast to checked_cast to achi
| |
| 115 return success; | |
| 116 } | |
| 117 | |
| 109 bool PickleIterator::ReadFloat(float* result) { | 118 bool PickleIterator::ReadFloat(float* result) { |
| 110 // crbug.com/315213 | 119 // crbug.com/315213 |
| 111 // The source data may not be properly aligned, and unaligned float reads | 120 // 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 | 121 // cause SIGBUS on some ARM platforms, so force using memcpy to copy the data |
| 113 // into the result. | 122 // into the result. |
| 114 const char* read_from = GetReadPointerAndAdvance<float>(); | 123 const char* read_from = GetReadPointerAndAdvance<float>(); |
| 115 if (!read_from) | 124 if (!read_from) |
| 116 return false; | 125 return false; |
| 117 memcpy(result, read_from, sizeof(*result)); | 126 memcpy(result, read_from, sizeof(*result)); |
| 118 return true; | 127 return true; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 if (new_size > capacity_after_header_) { | 362 if (new_size > capacity_after_header_) { |
| 354 Resize(std::max(capacity_after_header_ * 2, new_size)); | 363 Resize(std::max(capacity_after_header_ * 2, new_size)); |
| 355 } | 364 } |
| 356 | 365 |
| 357 char* write = mutable_payload() + write_offset_; | 366 char* write = mutable_payload() + write_offset_; |
| 358 memcpy(write, data, length); | 367 memcpy(write, data, length); |
| 359 memset(write + length, 0, data_len - length); | 368 memset(write + length, 0, data_len - length); |
| 360 header_->payload_size = static_cast<uint32>(new_size); | 369 header_->payload_size = static_cast<uint32>(new_size); |
| 361 write_offset_ = new_size; | 370 write_offset_ = new_size; |
| 362 } | 371 } |
| OLD | NEW |