Cleanups from stricter span usage of size_t: net
More use of first(), compile-time sizes, etc. Bug: none Change-Id: Idc0bc924edcd456d60fc7fde57e0491f6fc7311f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6027100 Reviewed-by: Adam Rice <ricea@chromium.org> Commit-Queue: Adam Rice <ricea@chromium.org> Auto-Submit: Peter Kasting <pkasting@chromium.org> Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Cr-Commit-Position: refs/heads/main@{#1384120}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
e1aa4cf01f
commit
c588bd45e4
net
base
cert_net
shared_dictionary
socket
spdy
test
embedded_test_server
websockets
@@ -53,7 +53,7 @@ std::string LoadFlagsToString(int load_flags) {
|
|||||||
flag_names.reserve(expected_size);
|
flag_names.reserve(expected_size);
|
||||||
// Skip the first entry in kInfo as including LOAD_NORMAL in the output would
|
// Skip the first entry in kInfo as including LOAD_NORMAL in the output would
|
||||||
// be confusing.
|
// be confusing.
|
||||||
for (const auto& flag : base::span(kInfo).subspan(1)) {
|
for (const auto& flag : base::span(kInfo).subspan<1>()) {
|
||||||
if (load_flags & flag.value) {
|
if (load_flags & flag.value) {
|
||||||
flag_names.push_back(flag.name);
|
flag_names.push_back(flag.name);
|
||||||
}
|
}
|
||||||
|
@@ -113,7 +113,7 @@ bool FixedSetIncrementalLookup::Advance(char input) {
|
|||||||
// If this is not the last character in the label, the next byte should
|
// If this is not the last character in the label, the next byte should
|
||||||
// be interpreted as a character or return value. Otherwise, the next
|
// be interpreted as a character or return value. Otherwise, the next
|
||||||
// byte should be interpreted as a list of child node offsets.
|
// byte should be interpreted as a list of child node offsets.
|
||||||
bytes_ = bytes_.subspan(1);
|
bytes_ = bytes_.subspan<1>();
|
||||||
DCHECK(!bytes_.empty());
|
DCHECK(!bytes_.empty());
|
||||||
bytes_starts_with_label_character_ = !is_last_char_in_label;
|
bytes_starts_with_label_character_ = !is_last_char_in_label;
|
||||||
return true;
|
return true;
|
||||||
@@ -144,7 +144,7 @@ bool FixedSetIncrementalLookup::Advance(char input) {
|
|||||||
// should be interpreted as a character or return value. Otherwise,
|
// should be interpreted as a character or return value. Otherwise,
|
||||||
// the next byte should be interpreted as a list of child node
|
// the next byte should be interpreted as a list of child node
|
||||||
// offsets.
|
// offsets.
|
||||||
bytes_ = offset_bytes.subspan(1);
|
bytes_ = offset_bytes.subspan<1>();
|
||||||
DCHECK(!bytes_.empty());
|
DCHECK(!bytes_.empty());
|
||||||
bytes_starts_with_label_character_ = !is_last_char_in_label;
|
bytes_starts_with_label_character_ = !is_last_char_in_label;
|
||||||
return true;
|
return true;
|
||||||
|
@@ -635,7 +635,7 @@ bool Job::ConsumeBytesRead(URLRequest* request, int num_bytes) {
|
|||||||
|
|
||||||
// Append the data to |response_body_|.
|
// Append the data to |response_body_|.
|
||||||
response_body_.reserve(response_body_.size() + num_bytes_s);
|
response_body_.reserve(response_body_.size() + num_bytes_s);
|
||||||
base::Extend(response_body_, read_buffer_->span().subspan(0, num_bytes_s));
|
base::Extend(response_body_, read_buffer_->span().first(num_bytes_s));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,12 +22,12 @@ static constexpr size_t kCompressionTypeBrotliSignatureSize =
|
|||||||
sizeof(kCompressionTypeBrotliSignature);
|
sizeof(kCompressionTypeBrotliSignature);
|
||||||
static constexpr size_t kCompressionTypeZstdSignatureSize =
|
static constexpr size_t kCompressionTypeZstdSignatureSize =
|
||||||
sizeof(kCompressionTypeZstdSignature);
|
sizeof(kCompressionTypeZstdSignature);
|
||||||
static constexpr int kCompressionDictionaryHashSize = 32;
|
static constexpr size_t kCompressionDictionaryHashSize = 32;
|
||||||
static_assert(sizeof(SHA256HashValue) == kCompressionDictionaryHashSize,
|
static_assert(sizeof(SHA256HashValue) == kCompressionDictionaryHashSize,
|
||||||
"kCompressionDictionaryHashSize mismatch");
|
"kCompressionDictionaryHashSize mismatch");
|
||||||
static constexpr int kCompressionTypeBrotliHeaderSize =
|
static constexpr size_t kCompressionTypeBrotliHeaderSize =
|
||||||
kCompressionTypeBrotliSignatureSize + kCompressionDictionaryHashSize;
|
kCompressionTypeBrotliSignatureSize + kCompressionDictionaryHashSize;
|
||||||
static constexpr int kCompressionTypeZstdHeaderSize =
|
static constexpr size_t kCompressionTypeZstdHeaderSize =
|
||||||
kCompressionTypeZstdSignatureSize + kCompressionDictionaryHashSize;
|
kCompressionTypeZstdSignatureSize + kCompressionDictionaryHashSize;
|
||||||
|
|
||||||
size_t GetSignatureSize(SharedDictionaryHeaderCheckerSourceStream::Type type) {
|
size_t GetSignatureSize(SharedDictionaryHeaderCheckerSourceStream::Type type) {
|
||||||
@@ -171,7 +171,7 @@ void SharedDictionaryHeaderCheckerSourceStream::HeaderCheckCompleted(
|
|||||||
|
|
||||||
base::span<const unsigned char>
|
base::span<const unsigned char>
|
||||||
SharedDictionaryHeaderCheckerSourceStream::GetSignatureInBuffer() const {
|
SharedDictionaryHeaderCheckerSourceStream::GetSignatureInBuffer() const {
|
||||||
return head_read_buffer_->everything().subspan(0, GetSignatureSize(type_));
|
return head_read_buffer_->everything().first(GetSignatureSize(type_));
|
||||||
}
|
}
|
||||||
|
|
||||||
base::span<const unsigned char>
|
base::span<const unsigned char>
|
||||||
|
@@ -336,8 +336,7 @@ const MockWrite& StaticSocketDataHelper::PeekRealWrite() const {
|
|||||||
return writes_[i];
|
return writes_[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK(false) << "No write data available.";
|
NOTREACHED() << "No write data available.";
|
||||||
return writes_[0]; // Avoid warning about unreachable missing return.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticSocketDataProvider::StaticSocketDataProvider()
|
StaticSocketDataProvider::StaticSocketDataProvider()
|
||||||
|
@@ -374,7 +374,7 @@ MockTransportClientSocketFactory::CreateTransportClientSocket(
|
|||||||
Rule rule(client_socket_type_);
|
Rule rule(client_socket_type_);
|
||||||
if (!rules_.empty()) {
|
if (!rules_.empty()) {
|
||||||
rule = rules_.front();
|
rule = rules_.front();
|
||||||
rules_ = rules_.subspan(1);
|
rules_ = rules_.subspan<1>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rule.expected_addresses) {
|
if (rule.expected_addresses) {
|
||||||
|
@@ -412,9 +412,10 @@ class SpdyNetworkTransactionTest
|
|||||||
|
|
||||||
void UseComplexPostRequest() {
|
void UseComplexPostRequest() {
|
||||||
ASSERT_FALSE(upload_data_stream_);
|
ASSERT_FALSE(upload_data_stream_);
|
||||||
const int kFileRangeOffset = 1;
|
static constexpr size_t kFileRangeOffset = 1;
|
||||||
const int kFileRangeLength = 3;
|
static constexpr size_t kFileRangeLength = 3;
|
||||||
CHECK_LT(kFileRangeOffset + kFileRangeLength, kUploadDataSize);
|
CHECK_LT(static_cast<int>(kFileRangeOffset + kFileRangeLength),
|
||||||
|
kUploadDataSize);
|
||||||
|
|
||||||
base::FilePath file_path;
|
base::FilePath file_path;
|
||||||
CHECK(base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &file_path));
|
CHECK(base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &file_path));
|
||||||
@@ -422,14 +423,13 @@ class SpdyNetworkTransactionTest
|
|||||||
|
|
||||||
std::vector<std::unique_ptr<UploadElementReader>> element_readers;
|
std::vector<std::unique_ptr<UploadElementReader>> element_readers;
|
||||||
element_readers.push_back(std::make_unique<UploadBytesElementReader>(
|
element_readers.push_back(std::make_unique<UploadBytesElementReader>(
|
||||||
base::byte_span_from_cstring(kUploadData)
|
base::byte_span_from_cstring(kUploadData).first<kFileRangeOffset>()));
|
||||||
.first(base::checked_cast<size_t>(kFileRangeOffset))));
|
|
||||||
element_readers.push_back(std::make_unique<UploadFileElementReader>(
|
element_readers.push_back(std::make_unique<UploadFileElementReader>(
|
||||||
base::SingleThreadTaskRunner::GetCurrentDefault().get(), file_path,
|
base::SingleThreadTaskRunner::GetCurrentDefault().get(), file_path,
|
||||||
kFileRangeOffset, kFileRangeLength, base::Time()));
|
kFileRangeOffset, kFileRangeLength, base::Time()));
|
||||||
element_readers.push_back(std::make_unique<UploadBytesElementReader>(
|
element_readers.push_back(std::make_unique<UploadBytesElementReader>(
|
||||||
base::byte_span_from_cstring(kUploadData)
|
base::byte_span_from_cstring(kUploadData)
|
||||||
.subspan(kFileRangeOffset + kFileRangeLength)));
|
.subspan<kFileRangeOffset + kFileRangeLength>()));
|
||||||
upload_data_stream_ = std::make_unique<ElementsUploadDataStream>(
|
upload_data_stream_ = std::make_unique<ElementsUploadDataStream>(
|
||||||
std::move(element_readers), 0);
|
std::move(element_readers), 0);
|
||||||
|
|
||||||
|
@@ -263,7 +263,7 @@ void WebSocketConnection::OnReadComplete(int result)
|
|||||||
}
|
}
|
||||||
|
|
||||||
base::span<uint8_t> data_span =
|
base::span<uint8_t> data_span =
|
||||||
read_buffer_->span().subspan(0, static_cast<size_t>(result));
|
read_buffer_->span().first(static_cast<size_t>(result));
|
||||||
|
|
||||||
WebSocketFrameParser parser;
|
WebSocketFrameParser parser;
|
||||||
std::vector<std::unique_ptr<WebSocketFrameChunk>> frame_chunks;
|
std::vector<std::unique_ptr<WebSocketFrameChunk>> frame_chunks;
|
||||||
|
@@ -35,9 +35,10 @@ void WebSocketSplitPacketCloseHandler::SendSplitCloseFrame() {
|
|||||||
// Split the close frame into two parts and send each separately.
|
// Split the close frame into two parts and send each separately.
|
||||||
const auto close_frame_span = close_frame->span();
|
const auto close_frame_span = close_frame->span();
|
||||||
|
|
||||||
const size_t split_index = 1; // Split after the first byte
|
// Split after the first byte
|
||||||
connection()->SendRaw(close_frame_span.subspan(0, split_index));
|
const auto [first, rest] = close_frame_span.split_at<1>();
|
||||||
connection()->SendRaw(close_frame_span.subspan(split_index));
|
connection()->SendRaw(first);
|
||||||
|
connection()->SendRaw(rest);
|
||||||
connection()->DisconnectAfterAnyWritesDone();
|
connection()->DisconnectAfterAnyWritesDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -156,7 +156,7 @@ size_t WebSocketFrameParser::DecodeFrameHeader(base::span<const uint8_t> data) {
|
|||||||
|
|
||||||
WebSocketMaskingKey masking_key = {};
|
WebSocketMaskingKey masking_key = {};
|
||||||
const bool masked = (second_byte & kMaskBit) != 0;
|
const bool masked = (second_byte & kMaskBit) != 0;
|
||||||
static constexpr int kMaskingKeyLength =
|
static constexpr size_t kMaskingKeyLength =
|
||||||
WebSocketFrameHeader::kMaskingKeyLength;
|
WebSocketFrameHeader::kMaskingKeyLength;
|
||||||
if (masked) {
|
if (masked) {
|
||||||
if (data.size() < current + kMaskingKeyLength)
|
if (data.size() < current + kMaskingKeyLength)
|
||||||
@@ -194,8 +194,7 @@ std::unique_ptr<WebSocketFrameChunk> WebSocketFrameParser::DecodeFramePayload(
|
|||||||
frame_chunk->final_chunk = false;
|
frame_chunk->final_chunk = false;
|
||||||
if (chunk_data_size) {
|
if (chunk_data_size) {
|
||||||
const auto split_point = base::checked_cast<size_t>(chunk_data_size);
|
const auto split_point = base::checked_cast<size_t>(chunk_data_size);
|
||||||
frame_chunk->payload =
|
frame_chunk->payload = base::as_writable_chars(data->first(split_point));
|
||||||
base::as_writable_chars(data->subspan(0, split_point));
|
|
||||||
*data = data->subspan(split_point);
|
*data = data->subspan(split_point);
|
||||||
frame_offset_ += chunk_data_size;
|
frame_offset_ += chunk_data_size;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user