| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <limits> | 10 #include <limits> |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 387 |
| 388 #ifdef ARCH_CPU_64_BITS | 388 #ifdef ARCH_CPU_64_BITS |
| 389 DCHECK_LE(length, std::numeric_limits<uint32>::max()); | 389 DCHECK_LE(length, std::numeric_limits<uint32>::max()); |
| 390 #endif | 390 #endif |
| 391 | 391 |
| 392 header_->payload_size = static_cast<uint32>(new_size); | 392 header_->payload_size = static_cast<uint32>(new_size); |
| 393 return payload() + offset; | 393 return payload() + offset; |
| 394 } | 394 } |
| 395 | 395 |
| 396 void Pickle::EndWrite(char* dest, int length) { | 396 void Pickle::EndWrite(char* dest, int length) { |
| 397 // Zero-pad to keep tools like purify from complaining about uninitialized | 397 // Zero-pad to keep tools like valgrind from complaining about uninitialized |
| 398 // memory. | 398 // memory. |
| 399 if (length % sizeof(uint32)) | 399 if (length % sizeof(uint32)) |
| 400 memset(dest + length, 0, sizeof(uint32) - (length % sizeof(uint32))); | 400 memset(dest + length, 0, sizeof(uint32) - (length % sizeof(uint32))); |
| 401 } | 401 } |
| 402 | 402 |
| 403 bool Pickle::Resize(size_t new_capacity) { | 403 bool Pickle::Resize(size_t new_capacity) { |
| 404 new_capacity = AlignInt(new_capacity, kPayloadUnit); | 404 new_capacity = AlignInt(new_capacity, kPayloadUnit); |
| 405 | 405 |
| 406 CHECK_NE(capacity_, kCapacityReadOnly); | 406 CHECK_NE(capacity_, kCapacityReadOnly); |
| 407 void* p = realloc(header_, new_capacity); | 407 void* p = realloc(header_, new_capacity); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 424 return NULL; | 424 return NULL; |
| 425 | 425 |
| 426 const Header* hdr = reinterpret_cast<const Header*>(start); | 426 const Header* hdr = reinterpret_cast<const Header*>(start); |
| 427 const char* payload_base = start + header_size; | 427 const char* payload_base = start + header_size; |
| 428 const char* payload_end = payload_base + hdr->payload_size; | 428 const char* payload_end = payload_base + hdr->payload_size; |
| 429 if (payload_end < payload_base) | 429 if (payload_end < payload_base) |
| 430 return NULL; | 430 return NULL; |
| 431 | 431 |
| 432 return (payload_end > end) ? NULL : payload_end; | 432 return (payload_end > end) ? NULL : payload_end; |
| 433 } | 433 } |
| OLD | NEW |