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

Side by Side Diff: net/server/web_socket_encoder.cc

Issue 1481403005: Fix size_t truncations in net for 64-bit VS 2015 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback Created 5 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
« no previous file with comments | « net/quic/quic_connection_test.cc ('k') | net/socket/socks5_client_socket_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/server/web_socket_encoder.h" 5 #include "net/server/web_socket_encoder.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 int masking_key, 142 int masking_key,
143 bool compressed, 143 bool compressed,
144 std::string* output) { 144 std::string* output) {
145 std::vector<char> frame; 145 std::vector<char> frame;
146 OpCode op_code = kOpCodeText; 146 OpCode op_code = kOpCodeText;
147 size_t data_length = message.length(); 147 size_t data_length = message.length();
148 148
149 int reserved1 = compressed ? kReserved1Bit : 0; 149 int reserved1 = compressed ? kReserved1Bit : 0;
150 frame.push_back(kFinalBit | op_code | reserved1); 150 frame.push_back(kFinalBit | op_code | reserved1);
151 char mask_key_bit = masking_key != 0 ? kMaskBit : 0; 151 char mask_key_bit = masking_key != 0 ? kMaskBit : 0;
152 if (data_length <= kMaxSingleBytePayloadLength) 152 if (data_length <= kMaxSingleBytePayloadLength) {
153 frame.push_back(data_length | mask_key_bit); 153 frame.push_back(static_cast<char>(data_length) | mask_key_bit);
154 else if (data_length <= 0xFFFF) { 154 } else if (data_length <= 0xFFFF) {
155 frame.push_back(kTwoBytePayloadLengthField | mask_key_bit); 155 frame.push_back(kTwoBytePayloadLengthField | mask_key_bit);
156 frame.push_back((data_length & 0xFF00) >> 8); 156 frame.push_back((data_length & 0xFF00) >> 8);
157 frame.push_back(data_length & 0xFF); 157 frame.push_back(data_length & 0xFF);
158 } else { 158 } else {
159 frame.push_back(kEightBytePayloadLengthField | mask_key_bit); 159 frame.push_back(kEightBytePayloadLengthField | mask_key_bit);
160 char extended_payload_length[8]; 160 char extended_payload_length[8];
161 size_t remaining = data_length; 161 size_t remaining = data_length;
162 // Fill the length into extended_payload_length in the network byte order. 162 // Fill the length into extended_payload_length in the network byte order.
163 for (int i = 0; i < 8; ++i) { 163 for (int i = 0; i < 8; ++i) {
164 extended_payload_length[7 - i] = remaining & 0xFF; 164 extended_payload_length[7 - i] = remaining & 0xFF;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 return false; 341 return false;
342 scoped_refptr<IOBufferWithSize> buffer = 342 scoped_refptr<IOBufferWithSize> buffer =
343 deflater_->GetOutput(deflater_->CurrentOutputSize()); 343 deflater_->GetOutput(deflater_->CurrentOutputSize());
344 if (!buffer.get()) 344 if (!buffer.get())
345 return false; 345 return false;
346 *output = std::string(buffer->data(), buffer->size()); 346 *output = std::string(buffer->data(), buffer->size());
347 return true; 347 return true;
348 } 348 }
349 349
350 } // namespace net 350 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection_test.cc ('k') | net/socket/socks5_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698