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 <algorithm> // for max() | 9 #include <algorithm> // for max() |
10 #include <limits> | 10 #include <limits> |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 variable_buffer_offset_ = | 362 variable_buffer_offset_ = |
363 data_ptr - reinterpret_cast<char*>(header_) - sizeof(int); | 363 data_ptr - reinterpret_cast<char*>(header_) - sizeof(int); |
364 | 364 |
365 // EndWrite doesn't necessarily have to be called after the write operation, | 365 // EndWrite doesn't necessarily have to be called after the write operation, |
366 // so we call it here to pad out what the caller will eventually write. | 366 // so we call it here to pad out what the caller will eventually write. |
367 EndWrite(data_ptr, length); | 367 EndWrite(data_ptr, length); |
368 return data_ptr; | 368 return data_ptr; |
369 } | 369 } |
370 | 370 |
371 void Pickle::TrimWriteData(int new_length) { | 371 void Pickle::TrimWriteData(int new_length) { |
372 DCHECK_NE(variable_buffer_offset_, 0); | 372 DCHECK_NE(variable_buffer_offset_, 0U); |
373 | 373 |
374 // Fetch the the variable buffer size | 374 // Fetch the the variable buffer size |
375 int* cur_length = reinterpret_cast<int*>( | 375 int* cur_length = reinterpret_cast<int*>( |
376 reinterpret_cast<char*>(header_) + variable_buffer_offset_); | 376 reinterpret_cast<char*>(header_) + variable_buffer_offset_); |
377 | 377 |
378 if (new_length < 0 || new_length > *cur_length) { | 378 if (new_length < 0 || new_length > *cur_length) { |
379 NOTREACHED() << "Invalid length in TrimWriteData."; | 379 NOTREACHED() << "Invalid length in TrimWriteData."; |
380 return; | 380 return; |
381 } | 381 } |
382 | 382 |
(...skipping 23 matching lines...) Expand all Loading... |
406 DCHECK(header_size <= static_cast<size_t>(kPayloadUnit)); | 406 DCHECK(header_size <= static_cast<size_t>(kPayloadUnit)); |
407 | 407 |
408 const Header* hdr = reinterpret_cast<const Header*>(start); | 408 const Header* hdr = reinterpret_cast<const Header*>(start); |
409 const char* payload_base = start + header_size; | 409 const char* payload_base = start + header_size; |
410 const char* payload_end = payload_base + hdr->payload_size; | 410 const char* payload_end = payload_base + hdr->payload_size; |
411 if (payload_end < payload_base) | 411 if (payload_end < payload_base) |
412 return NULL; | 412 return NULL; |
413 | 413 |
414 return (payload_end > end) ? NULL : payload_end; | 414 return (payload_end > end) ? NULL : payload_end; |
415 } | 415 } |
OLD | NEW |