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 17 matching lines...) Expand all Loading... | |
28 if (sizeof(Type) > sizeof(uint32)) | 28 if (sizeof(Type) > sizeof(uint32)) |
29 memcpy(result, read_from, sizeof(*result)); | 29 memcpy(result, read_from, sizeof(*result)); |
30 else | 30 else |
31 *result = *reinterpret_cast<const Type*>(read_from); | 31 *result = *reinterpret_cast<const Type*>(read_from); |
32 return true; | 32 return true; |
33 } | 33 } |
34 | 34 |
35 template<typename Type> | 35 template<typename Type> |
36 inline const char* PickleIterator::GetReadPointerAndAdvance() { | 36 inline const char* PickleIterator::GetReadPointerAndAdvance() { |
37 const char* current_read_ptr = read_ptr_; | 37 const char* current_read_ptr = read_ptr_; |
38 if (read_ptr_ + sizeof(Type) > read_end_ptr_) | 38 if (read_ptr_ + sizeof(Type) > read_end_ptr_) |
jar (doing other things)
2013/02/06 02:47:49
Should this to be re-phrased:
if (read_end_ptr_ -
| |
39 return NULL; | 39 return NULL; |
40 if (sizeof(Type) < sizeof(uint32)) | 40 if (sizeof(Type) < sizeof(uint32)) |
41 read_ptr_ += AlignInt(sizeof(Type), sizeof(uint32)); | 41 read_ptr_ += AlignInt(sizeof(Type), sizeof(uint32)); |
42 else | 42 else |
43 read_ptr_ += sizeof(Type); | 43 read_ptr_ += sizeof(Type); |
44 return current_read_ptr; | 44 return current_read_ptr; |
45 } | 45 } |
46 | 46 |
47 const char* PickleIterator::GetReadPointerAndAdvance(int num_bytes) { | 47 const char* PickleIterator::GetReadPointerAndAdvance(int num_bytes) { |
48 if (num_bytes < 0 || read_end_ptr_ - read_ptr_ < num_bytes) | 48 if (num_bytes < 0 || read_end_ptr_ - read_ptr_ < num_bytes) |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 const char* start, | 346 const char* start, |
347 const char* end) { | 347 const char* end) { |
348 DCHECK_EQ(header_size, AlignInt(header_size, sizeof(uint32))); | 348 DCHECK_EQ(header_size, AlignInt(header_size, sizeof(uint32))); |
349 DCHECK_LE(header_size, static_cast<size_t>(kPayloadUnit)); | 349 DCHECK_LE(header_size, static_cast<size_t>(kPayloadUnit)); |
350 | 350 |
351 if (static_cast<size_t>(end - start) < sizeof(Header)) | 351 if (static_cast<size_t>(end - start) < sizeof(Header)) |
352 return NULL; | 352 return NULL; |
353 | 353 |
354 const Header* hdr = reinterpret_cast<const Header*>(start); | 354 const Header* hdr = reinterpret_cast<const Header*>(start); |
355 const char* payload_base = start + header_size; | 355 const char* payload_base = start + header_size; |
356 const char* payload_end = payload_base + hdr->payload_size; | 356 if (hdr->payload_size > (uintptr_t) (end - payload_base)) |
jar (doing other things)
2013/02/06 02:47:49
nit: Please use static_cast<...>(...) instead of C
| |
357 if (payload_end < payload_base) | |
358 return NULL; | 357 return NULL; |
359 | 358 |
360 return (payload_end > end) ? NULL : payload_end; | 359 return payload_base + hdr->payload_size; |
361 } | 360 } |
OLD | NEW |