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

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

Issue 12091071: Make net::IOBuffer 64-bit safe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 10 months 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
« net/base/io_buffer.h ('K') | « net/base/io_buffer.h ('k') | no next file » | 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) 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 "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() 11 IOBuffer::IOBuffer()
12 : data_(NULL) { 12 : data_(NULL) {
13 } 13 }
14 14
15 IOBuffer::IOBuffer(int buffer_size) { 15 IOBuffer::IOBuffer(int buffer_size) {
16 DCHECK(buffer_size > 0); 16 CHECK_GT(buffer_size, 0);
17 data_ = new char[buffer_size]; 17 data_ = new char[buffer_size];
18 } 18 }
19 19
20 IOBuffer::IOBuffer(char* data) 20 IOBuffer::IOBuffer(char* data)
21 : data_(data) { 21 : data_(data) {
22 } 22 }
23 23
24 IOBuffer::~IOBuffer() { 24 IOBuffer::~IOBuffer() {
25 delete[] data_; 25 delete[] data_;
26 data_ = NULL; 26 data_ = NULL;
27 } 27 }
28 28
29 IOBufferWithSize::IOBufferWithSize(int size) 29 IOBufferWithSize::IOBufferWithSize(int size)
30 : IOBuffer(size), 30 : IOBuffer(size),
31 size_(size) { 31 size_(size) {
32 } 32 }
33 33
34 IOBufferWithSize::IOBufferWithSize(char* data, int size) 34 IOBufferWithSize::IOBufferWithSize(char* data, int size)
35 : IOBuffer(data), 35 : IOBuffer(data),
36 size_(size) { 36 size_(size) {
37 } 37 }
38 38
39 IOBufferWithSize::~IOBufferWithSize() { 39 IOBufferWithSize::~IOBufferWithSize() {
40 } 40 }
41 41
42 StringIOBuffer::StringIOBuffer(const std::string& s) 42 StringIOBuffer::StringIOBuffer(const std::string& s)
43 : IOBuffer(static_cast<char*>(NULL)), 43 : IOBuffer(static_cast<char*>(NULL)),
44 string_data_(s) { 44 string_data_(s) {
45 CHECK_LT(s.size(), static_cast<size_t>(INT_MAX));
45 data_ = const_cast<char*>(string_data_.data()); 46 data_ = const_cast<char*>(string_data_.data());
46 } 47 }
47 48
48 StringIOBuffer::~StringIOBuffer() { 49 StringIOBuffer::~StringIOBuffer() {
49 // We haven't allocated the buffer, so remove it before the base class 50 // We haven't allocated the buffer, so remove it before the base class
50 // destructor tries to delete[] it. 51 // destructor tries to delete[] it.
51 data_ = NULL; 52 data_ = NULL;
52 } 53 }
53 54
54 DrainableIOBuffer::DrainableIOBuffer(IOBuffer* base, int size) 55 DrainableIOBuffer::DrainableIOBuffer(IOBuffer* base, int size)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 130
130 WrappedIOBuffer::WrappedIOBuffer(const char* data) 131 WrappedIOBuffer::WrappedIOBuffer(const char* data)
131 : IOBuffer(const_cast<char*>(data)) { 132 : IOBuffer(const_cast<char*>(data)) {
132 } 133 }
133 134
134 WrappedIOBuffer::~WrappedIOBuffer() { 135 WrappedIOBuffer::~WrappedIOBuffer() {
135 data_ = NULL; 136 data_ = NULL;
136 } 137 }
137 138
138 } // namespace net 139 } // namespace net
OLDNEW
« net/base/io_buffer.h ('K') | « net/base/io_buffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698