Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: base/pickle.cc

Issue 601563003: Add Read/WriteSizeT() functions to the pickle layer, plus one consumer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test failure Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/pickle.h ('k') | base/pickle_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « base/pickle.h ('k') | base/pickle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698