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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 bool resized = Resize(payload_size); | 57 bool resized = Resize(payload_size); |
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) { |
cpu_(ooo_6.6-7.5)
2009/08/03 16:18:57
this operator is lacking a check against self assi
jar (doing other things)
2009/08/03 20:11:22
I'll create a CL that handles this explicitly.
| |
68 if (header_size_ != other.header_size_ && capacity_ != kCapacityReadOnly) { | 68 if (capacity_ == kCapacityReadOnly) { |
69 header_ = NULL; | |
70 capacity_ = 0; | |
71 } | |
72 if (header_size_ != other.header_size_) { | |
69 free(header_); | 73 free(header_); |
70 header_ = NULL; | 74 header_ = NULL; |
71 header_size_ = other.header_size_; | 75 header_size_ = other.header_size_; |
72 } | 76 } |
73 bool resized = Resize(other.header_size_ + other.header_->payload_size); | 77 bool resized = Resize(header_size_ + other.header_->payload_size); |
cpu_(ooo_6.6-7.5)
2009/08/03 16:18:57
I don't get the change in line 73. It seems more c
jar (doing other things)
2009/08/03 20:11:22
The goal was to have the argument of the memcpy (t
| |
74 CHECK(resized); // Realloc failed. | 78 CHECK(resized); // Realloc failed. |
75 memcpy(header_, other.header_, header_size_ + other.header_->payload_size); | 79 memcpy(header_, other.header_, header_size_ + other.header_->payload_size); |
76 variable_buffer_offset_ = other.variable_buffer_offset_; | 80 variable_buffer_offset_ = other.variable_buffer_offset_; |
77 return *this; | 81 return *this; |
78 } | 82 } |
79 | 83 |
80 bool Pickle::ReadBool(void** iter, bool* result) const { | 84 bool Pickle::ReadBool(void** iter, bool* result) const { |
81 DCHECK(iter); | 85 DCHECK(iter); |
82 | 86 |
83 int tmp; | 87 int tmp; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 } | 362 } |
359 | 363 |
360 // Update the payload size and variable buffer size | 364 // Update the payload size and variable buffer size |
361 header_->payload_size -= (*cur_length - new_length); | 365 header_->payload_size -= (*cur_length - new_length); |
362 *cur_length = new_length; | 366 *cur_length = new_length; |
363 } | 367 } |
364 | 368 |
365 bool Pickle::Resize(size_t new_capacity) { | 369 bool Pickle::Resize(size_t new_capacity) { |
366 new_capacity = AlignInt(new_capacity, kPayloadUnit); | 370 new_capacity = AlignInt(new_capacity, kPayloadUnit); |
367 | 371 |
372 CHECK(capacity_ != kCapacityReadOnly); | |
368 void* p = realloc(header_, new_capacity); | 373 void* p = realloc(header_, new_capacity); |
369 if (!p) | 374 if (!p) |
370 return false; | 375 return false; |
371 | 376 |
372 header_ = reinterpret_cast<Header*>(p); | 377 header_ = reinterpret_cast<Header*>(p); |
373 capacity_ = new_capacity; | 378 capacity_ = new_capacity; |
374 return true; | 379 return true; |
375 } | 380 } |
376 | 381 |
377 // static | 382 // static |
378 const char* Pickle::FindNext(size_t header_size, | 383 const char* Pickle::FindNext(size_t header_size, |
379 const char* start, | 384 const char* start, |
380 const char* end) { | 385 const char* end) { |
381 DCHECK(header_size == AlignInt(header_size, sizeof(uint32))); | 386 DCHECK(header_size == AlignInt(header_size, sizeof(uint32))); |
382 DCHECK(header_size <= static_cast<size_t>(kPayloadUnit)); | 387 DCHECK(header_size <= static_cast<size_t>(kPayloadUnit)); |
383 | 388 |
384 const Header* hdr = reinterpret_cast<const Header*>(start); | 389 const Header* hdr = reinterpret_cast<const Header*>(start); |
385 const char* payload_base = start + header_size; | 390 const char* payload_base = start + header_size; |
386 const char* payload_end = payload_base + hdr->payload_size; | 391 const char* payload_end = payload_base + hdr->payload_size; |
387 if (payload_end < payload_base) | 392 if (payload_end < payload_base) |
388 return NULL; | 393 return NULL; |
389 | 394 |
390 return (payload_end > end) ? NULL : payload_end; | 395 return (payload_end > end) ? NULL : payload_end; |
391 } | 396 } |
OLD | NEW |