| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // If there is anything wrong with the data, we're not going to use it. | 247 // If there is anything wrong with the data, we're not going to use it. |
| 248 if (!header_size_) | 248 if (!header_size_) |
| 249 header_ = NULL; | 249 header_ = NULL; |
| 250 } | 250 } |
| 251 | 251 |
| 252 Pickle::Pickle(const Pickle& other) | 252 Pickle::Pickle(const Pickle& other) |
| 253 : header_(NULL), | 253 : header_(NULL), |
| 254 header_size_(other.header_size_), | 254 header_size_(other.header_size_), |
| 255 capacity_after_header_(0), | 255 capacity_after_header_(0), |
| 256 write_offset_(other.write_offset_) { | 256 write_offset_(other.write_offset_) { |
| 257 size_t payload_size = header_size_ + other.header_->payload_size; | 257 Resize(other.header_->payload_size); |
| 258 Resize(payload_size); | 258 memcpy(header_, other.header_, header_size_ + other.header_->payload_size); |
| 259 memcpy(header_, other.header_, payload_size); | |
| 260 } | 259 } |
| 261 | 260 |
| 262 Pickle::~Pickle() { | 261 Pickle::~Pickle() { |
| 263 if (capacity_after_header_ != kCapacityReadOnly) | 262 if (capacity_after_header_ != kCapacityReadOnly) |
| 264 free(header_); | 263 free(header_); |
| 265 } | 264 } |
| 266 | 265 |
| 267 Pickle& Pickle::operator=(const Pickle& other) { | 266 Pickle& Pickle::operator=(const Pickle& other) { |
| 268 if (this == &other) { | 267 if (this == &other) { |
| 269 NOTREACHED(); | 268 NOTREACHED(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 } | 379 } |
| 381 | 380 |
| 382 char* write = mutable_payload() + write_offset_; | 381 char* write = mutable_payload() + write_offset_; |
| 383 memcpy(write, data, length); | 382 memcpy(write, data, length); |
| 384 memset(write + length, 0, data_len - length); | 383 memset(write + length, 0, data_len - length); |
| 385 header_->payload_size = static_cast<uint32>(new_size); | 384 header_->payload_size = static_cast<uint32>(new_size); |
| 386 write_offset_ = new_size; | 385 write_offset_ = new_size; |
| 387 } | 386 } |
| 388 | 387 |
| 389 } // namespace base | 388 } // namespace base |
| OLD | NEW |