Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: net/base/io_buffer.cc

Issue 418035: A large Content-Length header followed by a connection close could trigger an... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/http/http_network_transaction_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "net/base/io_buffer.h" 5 #include "net/base/io_buffer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace net { 9 namespace net {
10 10
11 IOBuffer::IOBuffer(int buffer_size) { 11 IOBuffer::IOBuffer(int buffer_size) {
12 DCHECK(buffer_size > 0); 12 DCHECK(buffer_size > 0);
13 data_ = new char[buffer_size]; 13 data_ = new char[buffer_size];
14 } 14 }
15 15
16 void DrainableIOBuffer::SetOffset(int bytes) { 16 void DrainableIOBuffer::SetOffset(int bytes) {
17 DCHECK(bytes >= 0 && bytes <= size_); 17 DCHECK(bytes >= 0 && bytes <= size_);
18 used_ = bytes; 18 used_ = bytes;
19 data_ = base_->data() + used_; 19 data_ = base_->data() + used_;
20 } 20 }
21 21
22 void GrowableIOBuffer::SetCapacity(int capacity) { 22 void GrowableIOBuffer::SetCapacity(int capacity) {
23 CHECK(capacity >= 0); 23 DCHECK(capacity >= 0);
24 // realloc will crash if it fails. 24 // realloc will crash if it fails.
25 real_data_.reset(static_cast<char*>(realloc(real_data_.release(), capacity))); 25 real_data_.reset(static_cast<char*>(realloc(real_data_.release(), capacity)));
26 // Sanity check.
27 CHECK(real_data_.get() != NULL || capacity == 0);
28 capacity_ = capacity; 26 capacity_ = capacity;
29 if (offset_ > capacity) 27 if (offset_ > capacity)
30 set_offset(capacity); 28 set_offset(capacity);
31 else 29 else
32 set_offset(offset_); // The pointer may have changed. 30 set_offset(offset_); // The pointer may have changed.
33 } 31 }
34 32
35 void GrowableIOBuffer::set_offset(int offset) { 33 void GrowableIOBuffer::set_offset(int offset) {
36 DCHECK(offset >= 0 && offset <= capacity_); 34 DCHECK(offset >= 0 && offset <= capacity_);
37 offset_ = offset; 35 offset_ = offset;
38 data_ = real_data_.get() + offset; 36 data_ = real_data_.get() + offset;
39 } 37 }
40 38
41 } // namespace net 39 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698