OLD | NEW |
1 // Copyright (c) 2006-2008 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> |
11 | 11 |
(...skipping 14 matching lines...) Expand all Loading... |
26 variable_buffer_offset_(0) { | 26 variable_buffer_offset_(0) { |
27 Resize(kPayloadUnit); | 27 Resize(kPayloadUnit); |
28 header_->payload_size = 0; | 28 header_->payload_size = 0; |
29 } | 29 } |
30 | 30 |
31 Pickle::Pickle(int header_size) | 31 Pickle::Pickle(int header_size) |
32 : header_(NULL), | 32 : header_(NULL), |
33 header_size_(AlignInt(header_size, sizeof(uint32))), | 33 header_size_(AlignInt(header_size, sizeof(uint32))), |
34 capacity_(0), | 34 capacity_(0), |
35 variable_buffer_offset_(0) { | 35 variable_buffer_offset_(0) { |
36 DCHECK(static_cast<size_t>(header_size) >= sizeof(Header)); | 36 DCHECK_GE(static_cast<size_t>(header_size), sizeof(Header)); |
37 DCHECK(header_size <= kPayloadUnit); | 37 DCHECK(header_size <= kPayloadUnit); |
38 Resize(kPayloadUnit); | 38 Resize(kPayloadUnit); |
39 header_->payload_size = 0; | 39 header_->payload_size = 0; |
40 } | 40 } |
41 | 41 |
42 Pickle::Pickle(const char* data, int data_len) | 42 Pickle::Pickle(const char* data, int data_len) |
43 : header_(reinterpret_cast<Header*>(const_cast<char*>(data))), | 43 : header_(reinterpret_cast<Header*>(const_cast<char*>(data))), |
44 header_size_(0), | 44 header_size_(0), |
45 capacity_(kCapacityReadOnly), | 45 capacity_(kCapacityReadOnly), |
46 variable_buffer_offset_(0) { | 46 variable_buffer_offset_(0) { |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |