diff options
author | deanm@google.com <deanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-07 13:40:16 +0000 |
---|---|---|
committer | deanm@google.com <deanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-07 13:40:16 +0000 |
commit | d26cd52757991911c111279e900d732ba283dd05 (patch) | |
tree | 1ed17eca0119921798175038aa8e3786902ebf57 /base/pickle.cc | |
parent | f1f642879ba2c3e7edb3af50d70ea11286f3ae93 (diff) | |
download | chromium_src-d26cd52757991911c111279e900d732ba283dd05.zip chromium_src-d26cd52757991911c111279e900d732ba283dd05.tar.gz chromium_src-d26cd52757991911c111279e900d732ba283dd05.tar.bz2 |
Some cross platform changes and general cleanups to Pickle.
- Clean up TrimWriteData, and remove the unneeded VariableLengthBuffer struct.
Modify a test to slightly test TrimWriteData, but it probably deserves more.
- Remove unneeded includes in pickle_unittest, including windows.h.
- According to 3.5 of the C++ standard, CustomHeader could not be used as a
template argument, because it had no linkage. This now builds on GCC.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@508 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/pickle.cc')
-rw-r--r-- | base/pickle.cc | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/base/pickle.cc b/base/pickle.cc index 0fb1d9c..356d5df 100644 --- a/base/pickle.cc +++ b/base/pickle.cc @@ -309,20 +309,21 @@ char* Pickle::BeginWriteData(int length) { return data_ptr; } -void Pickle::TrimWriteData(int length) { +void Pickle::TrimWriteData(int new_length) { DCHECK(variable_buffer_offset_ != 0); - VariableLengthBuffer *buffer = reinterpret_cast<VariableLengthBuffer*>( + // Fetch the the variable buffer size + int* cur_length = reinterpret_cast<int*>( reinterpret_cast<char*>(header_) + variable_buffer_offset_); - DCHECK_GE(buffer->length, length); - - int old_length = buffer->length; - int trimmed_bytes = old_length - length; - if (trimmed_bytes > 0) { - header_->payload_size -= trimmed_bytes; - buffer->length = length; + if (new_length < 0 || new_length > *cur_length) { + NOTREACHED() << "Invalid length in TrimWriteData."; + return; } + + // Update the payload size and variable buffer size + header_->payload_size -= (*cur_length - new_length); + *cur_length = new_length; } bool Pickle::Resize(size_t new_capacity) { |