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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // The source data may not be properly aligned, and unaligned float reads | 111 // 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 | 112 // cause SIGBUS on some ARM platforms, so force using memcpy to copy the data |
113 // into the result. | 113 // into the result. |
114 const char* read_from = GetReadPointerAndAdvance<float>(); | 114 const char* read_from = GetReadPointerAndAdvance<float>(); |
115 if (!read_from) | 115 if (!read_from) |
116 return false; | 116 return false; |
117 memcpy(result, read_from, sizeof(*result)); | 117 memcpy(result, read_from, sizeof(*result)); |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
| 121 bool PickleIterator::ReadDouble(double* result) { |
| 122 // crbug.com/315213 |
| 123 // The source data may not be properly aligned, and unaligned double reads |
| 124 // cause SIGBUS on some ARM platforms, so force using memcpy to copy the data |
| 125 // into the result. |
| 126 const char* read_from = GetReadPointerAndAdvance<double>(); |
| 127 if (!read_from) |
| 128 return false; |
| 129 memcpy(result, read_from, sizeof(*result)); |
| 130 return true; |
| 131 } |
| 132 |
121 bool PickleIterator::ReadString(std::string* result) { | 133 bool PickleIterator::ReadString(std::string* result) { |
122 int len; | 134 int len; |
123 if (!ReadInt(&len)) | 135 if (!ReadInt(&len)) |
124 return false; | 136 return false; |
125 const char* read_from = GetReadPointerAndAdvance(len); | 137 const char* read_from = GetReadPointerAndAdvance(len); |
126 if (!read_from) | 138 if (!read_from) |
127 return false; | 139 return false; |
128 | 140 |
129 result->assign(read_from, len); | 141 result->assign(read_from, len); |
130 return true; | 142 return true; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 if (new_size > capacity_after_header_) { | 353 if (new_size > capacity_after_header_) { |
342 Resize(std::max(capacity_after_header_ * 2, new_size)); | 354 Resize(std::max(capacity_after_header_ * 2, new_size)); |
343 } | 355 } |
344 | 356 |
345 char* write = mutable_payload() + write_offset_; | 357 char* write = mutable_payload() + write_offset_; |
346 memcpy(write, data, length); | 358 memcpy(write, data, length); |
347 memset(write + length, 0, data_len - length); | 359 memset(write + length, 0, data_len - length); |
348 header_->payload_size = static_cast<uint32>(new_size); | 360 header_->payload_size = static_cast<uint32>(new_size); |
349 write_offset_ = new_size; | 361 write_offset_ = new_size; |
350 } | 362 } |
OLD | NEW |