Fix and enable -Wshadow in third_party/quic Accidental variable shadowing is a common and scary source of bugs, [[citation needed]], and we should avoid doing so. This also lets us remove an undesirable -Wno-shadow on the chromium side. PiperOrigin-RevId: 596915336
diff --git a/quiche/balsa/balsa_headers.cc b/quiche/balsa/balsa_headers.cc index e6ee93c..6028a98 100644 --- a/quiche/balsa/balsa_headers.cc +++ b/quiche/balsa/balsa_headers.cc
@@ -1117,9 +1117,8 @@ // Tokenize just that line. BalsaHeaders::HeaderTokenList tokens; // Find where this line is stored. - const char* stream_begin = GetPtr(header_line->buffer_base_idx); absl::string_view value( - stream_begin + header_line->value_begin_idx, + GetPtr(header_line->buffer_base_idx) + header_line->value_begin_idx, header_line->last_char_idx - header_line->value_begin_idx); // Tokenize. ParseTokenList(value, &tokens); @@ -1136,7 +1135,7 @@ absl::string_view new_last_token = tokens[tokens.size() - 2]; const char* last_char_address = new_last_token.data() + new_last_token.size() - 1; - const char* stream_begin = GetPtr(header_line->buffer_base_idx); + const char* const stream_begin = GetPtr(header_line->buffer_base_idx); header_line->last_char_idx = last_char_address - stream_begin + 1; }
diff --git a/quiche/common/quiche_text_utils_test.cc b/quiche/common/quiche_text_utils_test.cc index aeaa940..cc62d78 100644 --- a/quiche/common/quiche_text_utils_test.cc +++ b/quiche/common/quiche_text_utils_test.cc
@@ -21,10 +21,8 @@ } TEST(QuicheTextUtilsTest, RemoveLeadingAndTrailingWhitespace) { - std::string input; - - for (auto* input : {"text", " text", " text", "text ", "text ", " text ", - " text ", "\r\n\ttext", "text\n\r\t"}) { + for (auto* const input : {"text", " text", " text", "text ", "text ", + " text ", " text ", "\r\n\ttext", "text\n\r\t"}) { absl::string_view piece(input); quiche::QuicheTextUtils::RemoveLeadingAndTrailingWhitespace(&piece); EXPECT_EQ("text", piece);
diff --git a/quiche/http2/adapter/oghttp2_session.cc b/quiche/http2/adapter/oghttp2_session.cc index 18a87d1..0242f40 100644 --- a/quiche/http2/adapter/oghttp2_session.cc +++ b/quiche/http2/adapter/oghttp2_session.cc
@@ -656,8 +656,8 @@ OgHttp2Session::SendResult OgHttp2Session::SendQueuedFrames() { // Flush any serialized prefix. - const SendResult result = MaybeSendBufferedData(); - if (result != SendResult::SEND_OK) { + if (const SendResult result = MaybeSendBufferedData(); + result != SendResult::SEND_OK) { return result; } // Serialize and send frames in the queue.
diff --git a/quiche/quic/core/crypto/client_proof_source.cc b/quiche/quic/core/crypto/client_proof_source.cc index 3bfe831..2d477db 100644 --- a/quiche/quic/core/crypto/client_proof_source.cc +++ b/quiche/quic/core/crypto/client_proof_source.cc
@@ -28,8 +28,8 @@ const ClientProofSource::CertAndKey* DefaultClientProofSource::GetCertAndKey( absl::string_view hostname) const { - const CertAndKey* result = LookupExact(hostname); - if (result != nullptr || hostname == "*") { + if (const CertAndKey* const result = LookupExact(hostname); + result || hostname == "*") { return result; } @@ -39,7 +39,7 @@ auto dot_pos = hostname.find('.'); if (dot_pos != std::string::npos) { std::string wildcard = absl::StrCat("*", hostname.substr(dot_pos)); - const CertAndKey* result = LookupExact(wildcard); + const CertAndKey* const result = LookupExact(wildcard); if (result != nullptr) { return result; }
diff --git a/quiche/quic/core/crypto/crypto_handshake_message.cc b/quiche/quic/core/crypto/crypto_handshake_message.cc index 9fa4dfa..eeb0215 100644 --- a/quiche/quic/core/crypto/crypto_handshake_message.cc +++ b/quiche/quic/core/crypto/crypto_handshake_message.cc
@@ -119,9 +119,7 @@ size_t num_tags = it->second.size() / sizeof(QuicTag); out_tags->resize(num_tags); for (size_t i = 0; i < num_tags; ++i) { - QuicTag tag; - memcpy(&tag, it->second.data() + i * sizeof(tag), sizeof(tag)); - (*out_tags)[i] = tag; + memcpy(&(*out_tags)[i], it->second.data() + i * sizeof(tag), sizeof(tag)); } return ret; }
diff --git a/quiche/quic/core/crypto/quic_crypto_server_config.cc b/quiche/quic/core/crypto/quic_crypto_server_config.cc index 69275dc..39ba6f3 100644 --- a/quiche/quic/core/crypto/quic_crypto_server_config.cc +++ b/quiche/quic/core/crypto/quic_crypto_server_config.cc
@@ -748,7 +748,7 @@ if (!context->signed_config()->chain) { const std::string chlo_hash = CryptoUtils::HashHandshakeMessage( context->client_hello(), Perspective::IS_SERVER); - const QuicSocketAddress server_address = context->server_address(); + const QuicSocketAddress context_server_address = context->server_address(); const std::string sni = std::string(context->info().sni); const QuicTransportVersion transport_version = context->transport_version(); @@ -756,7 +756,7 @@ this, std::move(context), configs); QUICHE_DCHECK(proof_source_.get()); - proof_source_->GetProof(server_address, client_address, sni, + proof_source_->GetProof(context_server_address, client_address, sni, configs.primary->serialized, transport_version, chlo_hash, std::move(cb)); return; @@ -1780,11 +1780,11 @@ // Some clients might still be using the old source token format so // attempt to parse that format. // TODO(rch): remove this code once the new format is ubiquitous. - SourceAddressToken token; - if (!token.ParseFromArray(plaintext.data(), plaintext.size())) { + SourceAddressToken old_source_token; + if (!old_source_token.ParseFromArray(plaintext.data(), plaintext.size())) { return SOURCE_ADDRESS_TOKEN_PARSE_FAILURE; } - *tokens.add_tokens() = token; + *tokens.add_tokens() = old_source_token; } return HANDSHAKE_OK;
diff --git a/quiche/quic/core/crypto/transport_parameters.cc b/quiche/quic/core/crypto/transport_parameters.cc index 1726ad3..af655d2 100644 --- a/quiche/quic/core/crypto/transport_parameters.cc +++ b/quiche/quic/core/crypto/transport_parameters.cc
@@ -1467,13 +1467,13 @@ } const uint8_t num_versions = versions_length / sizeof(uint32_t); for (uint8_t i = 0; i < num_versions; ++i) { - QuicVersionLabel version; - if (!value_reader.ReadUInt32(&version)) { + QuicVersionLabel parsed_version; + if (!value_reader.ReadUInt32(&parsed_version)) { *error_details = "Failed to parse Google supported version"; return false; } out->legacy_version_information->supported_versions.push_back( - version); + parsed_version); } } } break;
diff --git a/quiche/quic/core/quic_connection.cc b/quiche/quic/core/quic_connection.cc index dc84b68..3a3b356 100644 --- a/quiche/quic/core/quic_connection.cc +++ b/quiche/quic/core/quic_connection.cc
@@ -4534,13 +4534,13 @@ QuicErrorCode error, QuicIetfTransportErrorCodes ietf_error, const std::string& details) { // Always use the current path to send CONNECTION_CLOSE. - QuicPacketCreator::ScopedPeerAddressContext context( + QuicPacketCreator::ScopedPeerAddressContext peer_address_context( &packet_creator_, peer_address(), default_path_.client_connection_id, default_path_.server_connection_id); if (!SupportsMultiplePacketNumberSpaces()) { QUIC_DLOG(INFO) << ENDPOINT << "Sending connection close packet."; - ScopedEncryptionLevelContext context(this, - GetConnectionCloseEncryptionLevel()); + ScopedEncryptionLevelContext encryption_level_context( + this, GetConnectionCloseEncryptionLevel()); if (version().CanSendCoalescedPackets()) { coalesced_packet_.Clear(); } @@ -4554,11 +4554,9 @@ !packet_creator_.has_ack()) { SendAck(); } - QuicConnectionCloseFrame* frame; - - frame = new QuicConnectionCloseFrame(transport_version(), error, ietf_error, - details, - framer_.current_received_frame_type()); + QuicConnectionCloseFrame* const frame = new QuicConnectionCloseFrame( + transport_version(), error, ietf_error, details, + framer_.current_received_frame_type()); packet_creator_.ConsumeRetransmittableControlFrame(QuicFrame(frame)); packet_creator_.FlushCurrentPacket(); if (version().CanSendCoalescedPackets()) {
diff --git a/quiche/quic/core/quic_connection_context_test.cc b/quiche/quic/core/quic_connection_context_test.cc index 1f68ae9..58eb61b 100644 --- a/quiche/quic/core/quic_connection_context_test.cc +++ b/quiche/quic/core/quic_connection_context_test.cc
@@ -72,7 +72,7 @@ QUIC_TRACEPRINTF("%s %s %d", "outer", "printf", 0); { - QuicConnectionContextSwitcher switcher(&inner.context); + QuicConnectionContextSwitcher nested_switcher(&inner.context); QUIC_TRACELITERAL("inner literal"); QUIC_TRACESTRING(std::string("inner string")); QUIC_TRACEPRINTF("%s %s", "inner", "printf");
diff --git a/quiche/quic/core/quic_connection_test.cc b/quiche/quic/core/quic_connection_test.cc index c1f697c..bbdb4f4 100644 --- a/quiche/quic/core/quic_connection_test.cc +++ b/quiche/quic/core/quic_connection_test.cc
@@ -5270,14 +5270,16 @@ ASSERT_EQ(probe_packet_number, creator_->packet_number()); // Acknowledge all packets sent so far. - QuicAckFrame probe_ack = InitAckFrame(probe_packet_number); - EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _, _, _)) - .Times(AnyNumber()); - ProcessAckPacket(&probe_ack); - EXPECT_EQ(probe_size, connection_.max_packet_length()); - EXPECT_EQ(0u, connection_.GetBytesInFlight()); + { + QuicAckFrame probe_ack = InitAckFrame(probe_packet_number); + EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _, _, _)) + .Times(AnyNumber()); + ProcessAckPacket(&probe_ack); + EXPECT_EQ(probe_size, connection_.max_packet_length()); + EXPECT_EQ(0u, connection_.GetBytesInFlight()); - EXPECT_EQ(1u, connection_.mtu_probe_count()); + EXPECT_EQ(1u, connection_.mtu_probe_count()); + } QuicStreamOffset stream_offset = packets_between_probes_base; QuicByteCount last_probe_size = 0; @@ -5368,12 +5370,14 @@ ASSERT_EQ(probe_packet_number, creator_->packet_number()); // Acknowledge all packets sent so far. - QuicAckFrame probe_ack = InitAckFrame(probe_packet_number); - EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _, _, _)) - .Times(AnyNumber()); - ProcessAckPacket(&probe_ack); - EXPECT_EQ(probe_size, connection_.max_packet_length()); - EXPECT_EQ(0u, connection_.GetBytesInFlight()); + { + QuicAckFrame probe_ack = InitAckFrame(probe_packet_number); + EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _, _, _)) + .Times(AnyNumber()); + ProcessAckPacket(&probe_ack); + EXPECT_EQ(probe_size, connection_.max_packet_length()); + EXPECT_EQ(0u, connection_.GetBytesInFlight()); + } EXPECT_EQ(1u, connection_.mtu_probe_count()); @@ -5664,12 +5668,14 @@ ASSERT_EQ(probe_sequence_number, creator_->packet_number()); // Acknowledge all packets sent so far. - QuicAckFrame probe_ack = InitAckFrame(probe_sequence_number); - EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _, _, _)) - .Times(AnyNumber()); - ProcessAckPacket(&probe_ack); - EXPECT_EQ(probe_size, connection_.max_packet_length()); - EXPECT_EQ(0u, connection_.GetBytesInFlight()); + { + QuicAckFrame probe_ack = InitAckFrame(probe_sequence_number); + EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _, _, _)) + .Times(AnyNumber()); + ProcessAckPacket(&probe_ack); + EXPECT_EQ(probe_size, connection_.max_packet_length()); + EXPECT_EQ(0u, connection_.GetBytesInFlight()); + } EXPECT_EQ(1u, connection_.mtu_probe_count()); @@ -8315,13 +8321,15 @@ // Receive an ACK of the first packet. This should set the ping alarm with // initial retransmittable-on-wire timeout since there is no retransmittable // packet on the wire. - clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); - QuicAckFrame frame = - InitAckFrame({{QuicPacketNumber(1), QuicPacketNumber(2)}}); - ProcessAckPacket(&frame); - EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); - EXPECT_EQ(initial_retransmittable_on_wire_timeout, - connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + { + clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); + QuicAckFrame frame = + InitAckFrame({{QuicPacketNumber(1), QuicPacketNumber(2)}}); + ProcessAckPacket(&frame); + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(initial_retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + } // Simulate the alarm firing and check that a PING is sent. writer_->Reset(); @@ -8330,14 +8338,16 @@ // Receive an ACK for the previous PING. Ping alarm will be set with // aggressive timeout. - clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); - QuicPacketNumber ack_num = creator_->packet_number(); - frame = InitAckFrame( - {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); - ProcessAckPacket(&frame); - EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); - EXPECT_EQ(initial_retransmittable_on_wire_timeout, - connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + { + clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); + QuicPacketNumber ack_num = creator_->packet_number(); + QuicAckFrame frame = InitAckFrame( + {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); + ProcessAckPacket(&frame); + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(initial_retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + } // Process a data packet. EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); @@ -8353,7 +8363,7 @@ for (int i = 0; i < max_aggressive_retransmittable_on_wire_ping_count; i++) { // Receive an ACK of the previous packet. This should set the ping alarm // with the initial retransmittable-on-wire timeout. - QuicPacketNumber ack_num = creator_->packet_number(); + const QuicPacketNumber ack_num = creator_->packet_number(); QuicAckFrame frame = InitAckFrame( {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); ProcessAckPacket(&frame); @@ -8370,13 +8380,15 @@ // Receive another ACK for the previous PING. This should set the // ping alarm with backed off retransmittable-on-wire timeout. - ack_num = creator_->packet_number(); - frame = InitAckFrame( - {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); - ProcessAckPacket(&frame); - EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); - EXPECT_EQ(initial_retransmittable_on_wire_timeout * 2, - connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + { + const QuicPacketNumber ack_num = creator_->packet_number(); + QuicAckFrame frame = InitAckFrame( + {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); + ProcessAckPacket(&frame); + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(initial_retransmittable_on_wire_timeout * 2, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + } writer_->Reset(); clock_.AdvanceTime(2 * initial_retransmittable_on_wire_timeout); @@ -8384,18 +8396,20 @@ // Process another data packet and a new ACK packet. The ping alarm is set // with aggressive ping timeout again. - EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); - clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); - ProcessDataPacket(peer_creator_.packet_number() + 1); - QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, - peer_creator_.packet_number() + 1); - ack_num = creator_->packet_number(); - frame = InitAckFrame( - {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); - ProcessAckPacket(&frame); - EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); - EXPECT_EQ(initial_retransmittable_on_wire_timeout, - connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + { + EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); + clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); + ProcessDataPacket(peer_creator_.packet_number() + 1); + QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, + peer_creator_.packet_number() + 1); + const QuicPacketNumber ack_num = creator_->packet_number(); + QuicAckFrame frame = InitAckFrame( + {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); + ProcessAckPacket(&frame); + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(initial_retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + } } // Make sure that we never send more retransmissible on the wire pings than @@ -13235,20 +13249,22 @@ EXPECT_CALL(visitor_, ShouldKeepConnectionAlive()) .WillRepeatedly(Return(true)); - QuicNewConnectionIdFrame frame; - frame.connection_id = TestConnectionId(1234); - ASSERT_NE(frame.connection_id, connection_.connection_id()); - frame.stateless_reset_token = - QuicUtils::GenerateStatelessResetToken(frame.connection_id); - frame.retire_prior_to = 0u; - frame.sequence_number = 1u; - EXPECT_CALL(visitor_, CreateContextForMultiPortPath) - .WillRepeatedly(testing::WithArgs<0>([&](auto&& observer) { - observer->OnMultiPortPathContextAvailable( - std::move(std::make_unique<TestQuicPathValidationContext>( - kNewSelfAddress, connection_.peer_address(), &new_writer))); - })); - EXPECT_TRUE(connection_.OnNewConnectionIdFrame(frame)); + { + QuicNewConnectionIdFrame frame; + frame.connection_id = TestConnectionId(1234); + ASSERT_NE(frame.connection_id, connection_.connection_id()); + frame.stateless_reset_token = + QuicUtils::GenerateStatelessResetToken(frame.connection_id); + frame.retire_prior_to = 0u; + frame.sequence_number = 1u; + EXPECT_CALL(visitor_, CreateContextForMultiPortPath) + .WillRepeatedly(testing::WithArgs<0>([&](auto&& observer) { + observer->OnMultiPortPathContextAvailable( + std::move(std::make_unique<TestQuicPathValidationContext>( + kNewSelfAddress, connection_.peer_address(), &new_writer))); + })); + EXPECT_TRUE(connection_.OnNewConnectionIdFrame(frame)); + } EXPECT_TRUE(connection_.HasPendingPathValidation()); EXPECT_TRUE(QuicConnectionPeer::IsAlternativePath( &connection_, kNewSelfAddress, connection_.peer_address()));
diff --git a/quiche/quic/core/quic_linux_socket_utils_test.cc b/quiche/quic/core/quic_linux_socket_utils_test.cc index f38df83..cdf41c4 100644 --- a/quiche/quic/core/quic_linux_socket_utils_test.cc +++ b/quiche/quic/core/quic_linux_socket_utils_test.cc
@@ -135,9 +135,11 @@ QuicSocketAddress peer_addr(QuicIpAddress::Loopback4(), 1234); char packet_buf[1024]; - QuicMsgHdr quic_hdr(packet_buf, sizeof(packet_buf), peer_addr, nullptr, 0); - CheckMsghdrWithoutCbuf(quic_hdr.hdr(), packet_buf, sizeof(packet_buf), - peer_addr); + { + QuicMsgHdr quic_hdr(packet_buf, sizeof(packet_buf), peer_addr, nullptr, 0); + CheckMsghdrWithoutCbuf(quic_hdr.hdr(), packet_buf, sizeof(packet_buf), + peer_addr); + } for (bool is_ipv4 : {true, false}) { QuicIpAddress self_addr =
diff --git a/quiche/quic/core/quic_packet_creator_test.cc b/quiche/quic/core/quic_packet_creator_test.cc index 8c5b155..98dbfec 100644 --- a/quiche/quic/core/quic_packet_creator_test.cc +++ b/quiche/quic/core/quic_packet_creator_test.cc
@@ -4056,11 +4056,12 @@ // Send some stream data. EXPECT_CALL(delegate_, ShouldGeneratePacket(_, _)) .WillRepeatedly(Return(true)); - QuicConsumedData consumed = creator_.ConsumeData( - QuicUtils::GetFirstBidirectionalStreamId(creator_.transport_version(), - Perspective::IS_CLIENT), - "foo", 0, NO_FIN); - EXPECT_EQ(3u, consumed.bytes_consumed); + EXPECT_EQ(3u, creator_ + .ConsumeData(QuicUtils::GetFirstBidirectionalStreamId( + creator_.transport_version(), + Perspective::IS_CLIENT), + "foo", 0, NO_FIN) + .bytes_consumed); EXPECT_TRUE(creator_.HasPendingFrames()); { // Set the same address via context which should not trigger flush. @@ -4070,11 +4071,12 @@ ASSERT_EQ(server_connection_id, creator_.GetServerConnectionId()); EXPECT_TRUE(creator_.HasPendingFrames()); // Queue another STREAM_FRAME. - QuicConsumedData consumed = creator_.ConsumeData( - QuicUtils::GetFirstBidirectionalStreamId(creator_.transport_version(), - Perspective::IS_CLIENT), - "foo", 0, FIN); - EXPECT_EQ(3u, consumed.bytes_consumed); + EXPECT_EQ(3u, creator_ + .ConsumeData(QuicUtils::GetFirstBidirectionalStreamId( + creator_.transport_version(), + Perspective::IS_CLIENT), + "foo", 0, FIN) + .bytes_consumed); } // After exiting the scope, the last queued frame should be flushed. EXPECT_TRUE(creator_.HasPendingFrames()); @@ -4095,11 +4097,12 @@ // Send some stream data. EXPECT_CALL(delegate_, ShouldGeneratePacket(_, _)) .WillRepeatedly(Return(true)); - QuicConsumedData consumed = creator_.ConsumeData( - QuicUtils::GetFirstBidirectionalStreamId(creator_.transport_version(), - Perspective::IS_CLIENT), - "foo", 0, NO_FIN); - EXPECT_EQ(3u, consumed.bytes_consumed); + EXPECT_EQ(3u, creator_ + .ConsumeData(QuicUtils::GetFirstBidirectionalStreamId( + creator_.transport_version(), + Perspective::IS_CLIENT), + "foo", 0, NO_FIN) + .bytes_consumed); QuicSocketAddress peer_addr1(QuicIpAddress::Any4(), 12346); EXPECT_CALL(delegate_, OnSerializedPacket(_)) @@ -4124,11 +4127,12 @@ ASSERT_EQ(server_connection_id, creator_.GetServerConnectionId()); EXPECT_FALSE(creator_.HasPendingFrames()); // Queue another STREAM_FRAME. - QuicConsumedData consumed = creator_.ConsumeData( - QuicUtils::GetFirstBidirectionalStreamId(creator_.transport_version(), - Perspective::IS_CLIENT), - "foo", 0, FIN); - EXPECT_EQ(3u, consumed.bytes_consumed); + EXPECT_EQ(3u, creator_ + .ConsumeData(QuicUtils::GetFirstBidirectionalStreamId( + creator_.transport_version(), + Perspective::IS_CLIENT), + "foo", 0, FIN) + .bytes_consumed); EXPECT_TRUE(creator_.HasPendingFrames()); } // After exiting the scope, the last queued frame should be flushed. @@ -4149,11 +4153,12 @@ // Send some stream data. EXPECT_CALL(delegate_, ShouldGeneratePacket(_, _)) .WillRepeatedly(Return(true)); - QuicConsumedData consumed = creator_.ConsumeData( - QuicUtils::GetFirstBidirectionalStreamId(creator_.transport_version(), - Perspective::IS_CLIENT), - "foo", 0, NO_FIN); - EXPECT_EQ(3u, consumed.bytes_consumed); + EXPECT_EQ(3u, creator_ + .ConsumeData(QuicUtils::GetFirstBidirectionalStreamId( + creator_.transport_version(), + Perspective::IS_CLIENT), + "foo", 0, NO_FIN) + .bytes_consumed); EXPECT_TRUE(creator_.HasPendingFrames()); QuicSocketAddress peer_addr1(QuicIpAddress::Any4(), 12346); @@ -4173,11 +4178,12 @@ ASSERT_EQ(server_connection_id2, creator_.GetServerConnectionId()); EXPECT_CALL(delegate_, ShouldGeneratePacket(_, _)) .WillRepeatedly(Return(true)); - QuicConsumedData consumed = creator_.ConsumeData( - QuicUtils::GetFirstBidirectionalStreamId( - creator_.transport_version(), Perspective::IS_CLIENT), - "foo", 0, NO_FIN); - EXPECT_EQ(3u, consumed.bytes_consumed); + EXPECT_EQ(3u, creator_ + .ConsumeData(QuicUtils::GetFirstBidirectionalStreamId( + creator_.transport_version(), + Perspective::IS_CLIENT), + "foo", 0, NO_FIN) + .bytes_consumed); EXPECT_TRUE(creator_.HasPendingFrames()); // This should trigger another OnSerializedPacket() with the 2nd // address.
diff --git a/quiche/quic/core/quic_session.cc b/quiche/quic/core/quic_session.cc index 207b0e7..665e4ff 100644 --- a/quiche/quic/core/quic_session.cc +++ b/quiche/quic/core/quic_session.cc
@@ -2533,8 +2533,8 @@ QuicConnection::ScopedPacketFlusher retransmission_flusher(connection_); // Retransmit crypto data first. bool uses_crypto_frames = QuicVersionUsesCryptoFrames(transport_version()); - QuicCryptoStream* crypto_stream = GetMutableCryptoStream(); - if (uses_crypto_frames && crypto_stream->HasPendingCryptoRetransmission()) { + if (QuicCryptoStream* const crypto_stream = GetMutableCryptoStream(); + uses_crypto_frames && crypto_stream->HasPendingCryptoRetransmission()) { crypto_stream->WritePendingCryptoRetransmission(); } // Retransmit crypto data in stream 1 frames (version < 47). @@ -2542,7 +2542,7 @@ streams_with_pending_retransmission_.contains( QuicUtils::GetCryptoStreamId(transport_version()))) { // Retransmit crypto data first. - QuicStream* crypto_stream = + QuicStream* const crypto_stream = GetStream(QuicUtils::GetCryptoStreamId(transport_version())); crypto_stream->OnCanWrite(); QUICHE_DCHECK(CheckStreamWriteBlocked(crypto_stream));
diff --git a/quiche/quic/core/tls_server_handshaker.cc b/quiche/quic/core/tls_server_handshaker.cc index d141f1a..d819703 100644 --- a/quiche/quic/core/tls_server_handshaker.cc +++ b/quiche/quic/core/tls_server_handshaker.cc
@@ -587,10 +587,10 @@ if (level == ENCRYPTION_FORWARD_SECURE) { encryption_established_ = true; // Fill crypto_negotiated_params_: - const SSL_CIPHER* cipher = SSL_get_current_cipher(ssl()); - if (cipher) { + const SSL_CIPHER* ssl_cipher = SSL_get_current_cipher(ssl()); + if (ssl_cipher) { crypto_negotiated_params_->cipher_suite = - SSL_CIPHER_get_protocol_id(cipher); + SSL_CIPHER_get_protocol_id(ssl_cipher); } crypto_negotiated_params_->key_exchange_group = SSL_get_curve_id(ssl()); crypto_negotiated_params_->encrypted_client_hello = SSL_ech_accepted(ssl());
diff --git a/quiche/quic/tools/quic_memory_cache_backend.cc b/quiche/quic/tools/quic_memory_cache_backend.cc index 29434b3..74e2b91 100644 --- a/quiche/quic/tools/quic_memory_cache_backend.cc +++ b/quiche/quic/tools/quic_memory_cache_backend.cc
@@ -38,8 +38,7 @@ file_contents_ = *maybe_file_contents; // First read the headers. - size_t start = 0; - while (start < file_contents_.length()) { + for (size_t start = 0; start < file_contents_.length();) { size_t pos = file_contents_.find('\n', start); if (pos == std::string::npos) { QUIC_LOG(DFATAL) << "Headers invalid or empty, ignoring: " << file_name_; @@ -54,6 +53,8 @@ start = pos + 1; // Headers end with an empty line. if (line.empty()) { + body_ = absl::string_view(file_contents_.data() + start, + file_contents_.size() - start); break; } // Extract the status from the HTTP first line. @@ -82,8 +83,8 @@ spdy_headers_.erase("connection"); // Override the URL with the X-Original-Url header, if present. - auto it = spdy_headers_.find("x-original-url"); - if (it != spdy_headers_.end()) { + if (auto it = spdy_headers_.find("x-original-url"); + it != spdy_headers_.end()) { x_original_url_ = it->second; HandleXOriginalUrl(); } @@ -91,11 +92,9 @@ // X-Push-URL header is a relatively quick way to support sever push // in the toy server. A production server should use link=preload // stuff as described in https://w3c.github.io/preload/. - it = spdy_headers_.find("x-push-url"); - if (it != spdy_headers_.end()) { + if (auto it = spdy_headers_.find("x-push-url"); it != spdy_headers_.end()) { absl::string_view push_urls = it->second; - size_t start = 0; - while (start < push_urls.length()) { + for (size_t start = 0; start < push_urls.length();) { size_t pos = push_urls.find('\0', start); if (pos == std::string::npos) { push_urls_.push_back(absl::string_view(push_urls.data() + start, @@ -106,9 +105,6 @@ start += pos + 1; } } - - body_ = absl::string_view(file_contents_.data() + start, - file_contents_.size() - start); } void QuicMemoryCacheBackend::ResourceFile::SetHostPathFromBase(
diff --git a/quiche/quic/tools/quic_server.cc b/quiche/quic/tools/quic_server.cc index 91c6055..21a91a0 100644 --- a/quiche/quic/tools/quic_server.cc +++ b/quiche/quic/tools/quic_server.cc
@@ -138,12 +138,12 @@ QUIC_LOG(INFO) << "Listening on " << address.ToString(); port_ = address.port(); if (port_ == 0) { - QuicSocketAddress address; - if (address.FromSocket(fd_) != 0) { + QuicSocketAddress self_address; + if (self_address.FromSocket(fd_) != 0) { QUIC_LOG(ERROR) << "Unable to get self address. Error: " << strerror(errno); } - port_ = address.port(); + port_ = self_address.port(); } bool register_result = event_loop_->RegisterSocket(
diff --git a/quiche/spdy/core/spdy_framer_test.cc b/quiche/spdy/core/spdy_framer_test.cc index e1669aa..56d0207 100644 --- a/quiche/spdy/core/spdy_framer_test.cc +++ b/quiche/spdy/core/spdy_framer_test.cc
@@ -5010,17 +5010,17 @@ namespace { void CheckFrameAndIRSize(SpdyFrameIR* ir, SpdyFramer* framer, - ArrayOutputBuffer* output_buffer) { - output_buffer->Reset(); + ArrayOutputBuffer* array_output_buffer) { + array_output_buffer->Reset(); SpdyFrameType type = ir->frame_type(); size_t ir_size = ir->size(); - framer->SerializeFrame(*ir, output_buffer); + framer->SerializeFrame(*ir, array_output_buffer); if (type == SpdyFrameType::HEADERS || type == SpdyFrameType::PUSH_PROMISE) { // For HEADERS and PUSH_PROMISE, the size is an estimate. - EXPECT_GE(ir_size, output_buffer->Size() * 9 / 10); - EXPECT_LT(ir_size, output_buffer->Size() * 11 / 10); + EXPECT_GE(ir_size, array_output_buffer->Size() * 9 / 10); + EXPECT_LT(ir_size, array_output_buffer->Size() * 11 / 10); } else { - EXPECT_EQ(ir_size, output_buffer->Size()); + EXPECT_EQ(ir_size, array_output_buffer->Size()); } } } // namespace