| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <limits> | 9 #include <limits> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 CHECK(resized); // Realloc failed. | 58 CHECK(resized); // Realloc failed. |
| 59 memcpy(header_, other.header_, payload_size); | 59 memcpy(header_, other.header_, payload_size); |
| 60 } | 60 } |
| 61 | 61 |
| 62 Pickle::~Pickle() { | 62 Pickle::~Pickle() { |
| 63 if (capacity_ != kCapacityReadOnly) | 63 if (capacity_ != kCapacityReadOnly) |
| 64 free(header_); | 64 free(header_); |
| 65 } | 65 } |
| 66 | 66 |
| 67 Pickle& Pickle::operator=(const Pickle& other) { | 67 Pickle& Pickle::operator=(const Pickle& other) { |
| 68 if (this == &other) { |
| 69 NOTREACHED(); |
| 70 return *this; |
| 71 } |
| 68 if (capacity_ == kCapacityReadOnly) { | 72 if (capacity_ == kCapacityReadOnly) { |
| 69 header_ = NULL; | 73 header_ = NULL; |
| 70 capacity_ = 0; | 74 capacity_ = 0; |
| 71 } | 75 } |
| 72 if (header_size_ != other.header_size_) { | 76 if (header_size_ != other.header_size_) { |
| 73 free(header_); | 77 free(header_); |
| 74 header_ = NULL; | 78 header_ = NULL; |
| 75 header_size_ = other.header_size_; | 79 header_size_ = other.header_size_; |
| 76 } | 80 } |
| 77 bool resized = Resize(header_size_ + other.header_->payload_size); | 81 bool resized = Resize(other.header_size_ + other.header_->payload_size); |
| 78 CHECK(resized); // Realloc failed. | 82 CHECK(resized); // Realloc failed. |
| 79 memcpy(header_, other.header_, header_size_ + other.header_->payload_size); | 83 memcpy(header_, other.header_, |
| 84 other.header_size_ + other.header_->payload_size); |
| 80 variable_buffer_offset_ = other.variable_buffer_offset_; | 85 variable_buffer_offset_ = other.variable_buffer_offset_; |
| 81 return *this; | 86 return *this; |
| 82 } | 87 } |
| 83 | 88 |
| 84 bool Pickle::ReadBool(void** iter, bool* result) const { | 89 bool Pickle::ReadBool(void** iter, bool* result) const { |
| 85 DCHECK(iter); | 90 DCHECK(iter); |
| 86 | 91 |
| 87 int tmp; | 92 int tmp; |
| 88 if (!ReadInt(iter, &tmp)) | 93 if (!ReadInt(iter, &tmp)) |
| 89 return false; | 94 return false; |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 DCHECK(header_size <= static_cast<size_t>(kPayloadUnit)); | 392 DCHECK(header_size <= static_cast<size_t>(kPayloadUnit)); |
| 388 | 393 |
| 389 const Header* hdr = reinterpret_cast<const Header*>(start); | 394 const Header* hdr = reinterpret_cast<const Header*>(start); |
| 390 const char* payload_base = start + header_size; | 395 const char* payload_base = start + header_size; |
| 391 const char* payload_end = payload_base + hdr->payload_size; | 396 const char* payload_end = payload_base + hdr->payload_size; |
| 392 if (payload_end < payload_base) | 397 if (payload_end < payload_base) |
| 393 return NULL; | 398 return NULL; |
| 394 | 399 |
| 395 return (payload_end > end) ? NULL : payload_end; | 400 return (payload_end > end) ? NULL : payload_end; |
| 396 } | 401 } |
| OLD | NEW |