diff options
author | pkasting <pkasting@chromium.org> | 2014-10-01 20:01:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-02 03:01:21 +0000 |
commit | 89a19f1430afa495acfccbc3ed7da9f51a7911d1 (patch) | |
tree | c0034324912fd6e1057cbd57b7cacb6555f72a95 /base/pickle.cc | |
parent | 413cdda9719e7e8b4e9410a9b9630e684e29fc0c (diff) | |
download | chromium_src-89a19f1430afa495acfccbc3ed7da9f51a7911d1.zip chromium_src-89a19f1430afa495acfccbc3ed7da9f51a7911d1.tar.gz chromium_src-89a19f1430afa495acfccbc3ed7da9f51a7911d1.tar.bz2 |
Add Read/WriteSizeT() functions to the pickle layer, plus one consumer.
This eliminates the need for callers to do explicit conversions, and also
ensures callers don't try to implement pickling of a size_t using a 32-bit type,
leading to truncation on 64-bit targets. The pickle layer will ensure 64-bit
types are always used.
I'll be changing other callsites to use this in future patches.
BUG=none
TEST=none
Review URL: https://codereview.chromium.org/601563003
Cr-Commit-Position: refs/heads/master@{#297774}
Diffstat (limited to 'base/pickle.cc')
-rw-r--r-- | base/pickle.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/base/pickle.cc b/base/pickle.cc index 2d7a051..d461f41 100644 --- a/base/pickle.cc +++ b/base/pickle.cc @@ -106,6 +106,16 @@ bool PickleIterator::ReadUInt64(uint64* result) { return ReadBuiltinType(result); } +bool PickleIterator::ReadSizeT(size_t* result) { + // Always read size_t as a 64-bit value to ensure compatibility between 32-bit + // and 64-bit processes. + uint64 result_uint64 = 0; + bool success = ReadBuiltinType(&result_uint64); + *result = static_cast<size_t>(result_uint64); + // Fail if the cast above truncates the value. + return success && (*result == result_uint64); +} + bool PickleIterator::ReadFloat(float* result) { // crbug.com/315213 // The source data may not be properly aligned, and unaligned float reads |