Fix -Wc++11-narrowing in quiche. char is a signed type and cannot hold values >=0x80, so storing these results in a warning. Instead, store runs of bytes as uint8_t, and explicitly cast to char* where needed. See https://crbug.com/1216696. This CL is generated from https://quiche-review.googlesource.com/c/quiche/+/10700. Unfortunately QUICHE currently does not accept external contributions directly. PiperOrigin-RevId: 378433199
diff --git a/quic/core/http/http_encoder_test.cc b/quic/core/http/http_encoder_test.cc index 3032cd6..c2b0f36 100644 --- a/quic/core/http/http_encoder_test.cc +++ b/quic/core/http/http_encoder_test.cc
@@ -87,40 +87,42 @@ PriorityUpdateFrame priority_update1; priority_update1.prioritized_element_type = REQUEST_STREAM; priority_update1.prioritized_element_id = 0x03; - char output1[] = {0x80, 0x0f, 0x07, 0x00, // type (PRIORITY_UPDATE) - 0x01, // length - 0x03}; // prioritized element id + uint8_t output1[] = {0x80, 0x0f, 0x07, 0x00, // type (PRIORITY_UPDATE) + 0x01, // length + 0x03}; // prioritized element id std::unique_ptr<char[]> buffer; uint64_t length = HttpEncoder::SerializePriorityUpdateFrame(priority_update1, &buffer); EXPECT_EQ(ABSL_ARRAYSIZE(output1), length); - quiche::test::CompareCharArraysWithHexError("PRIORITY_UPDATE", buffer.get(), - length, output1, - ABSL_ARRAYSIZE(output1)); + quiche::test::CompareCharArraysWithHexError( + "PRIORITY_UPDATE", buffer.get(), length, reinterpret_cast<char*>(output1), + ABSL_ARRAYSIZE(output1)); } TEST(HttpEncoderTest, SerializeAcceptChFrame) { AcceptChFrame accept_ch; - char output1[] = {0x40, 0x89, // type (ACCEPT_CH) - 0x00}; // length + uint8_t output1[] = {0x40, 0x89, // type (ACCEPT_CH) + 0x00}; // length std::unique_ptr<char[]> buffer; uint64_t length = HttpEncoder::SerializeAcceptChFrame(accept_ch, &buffer); EXPECT_EQ(ABSL_ARRAYSIZE(output1), length); quiche::test::CompareCharArraysWithHexError("ACCEPT_CH", buffer.get(), length, - output1, ABSL_ARRAYSIZE(output1)); + reinterpret_cast<char*>(output1), + ABSL_ARRAYSIZE(output1)); accept_ch.entries.push_back({"foo", "bar"}); - char output2[] = {0x40, 0x89, // type (ACCEPT_CH) - 0x08, // payload length - 0x03, 0x66, 0x6f, 0x6f, // length of "foo"; "foo" - 0x03, 0x62, 0x61, 0x72}; // length of "bar"; "bar" + uint8_t output2[] = {0x40, 0x89, // type (ACCEPT_CH) + 0x08, // payload length + 0x03, 0x66, 0x6f, 0x6f, // length of "foo"; "foo" + 0x03, 0x62, 0x61, 0x72}; // length of "bar"; "bar" length = HttpEncoder::SerializeAcceptChFrame(accept_ch, &buffer); EXPECT_EQ(ABSL_ARRAYSIZE(output2), length); quiche::test::CompareCharArraysWithHexError("ACCEPT_CH", buffer.get(), length, - output2, ABSL_ARRAYSIZE(output2)); + reinterpret_cast<char*>(output2), + ABSL_ARRAYSIZE(output2)); } TEST(HttpEncoderTest, SerializeWebTransportStreamFrameHeader) {
diff --git a/quic/core/quic_connection_test.cc b/quic/core/quic_connection_test.cc index ea4ebfe..31dde85 100644 --- a/quic/core/quic_connection_test.cc +++ b/quic/core/quic_connection_test.cc
@@ -10545,16 +10545,16 @@ } // These values come from draft-ietf-quic-tls Appendix A.4. - char retry_packet_rfcv1[] = { + uint8_t retry_packet_rfcv1[] = { 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x04, 0xa2, 0x65, 0xba, 0x2e, 0xff, 0x4d, 0x82, 0x90, 0x58, 0xfb, 0x3f, 0x0f, 0x24, 0x96, 0xba}; - char retry_packet29[] = { + uint8_t retry_packet29[] = { 0xff, 0xff, 0x00, 0x00, 0x1d, 0x00, 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0xd1, 0x69, 0x26, 0xd8, 0x1f, 0x6f, 0x9c, 0xa2, 0x95, 0x3a, 0x8a, 0xa4, 0x57, 0x5e, 0x1e, 0x49}; - char* retry_packet; + uint8_t* retry_packet; size_t retry_packet_length; if (version() == ParsedQuicVersion::RFCv1()) { retry_packet = retry_packet_rfcv1; @@ -10568,19 +10568,21 @@ return; } - char original_connection_id_bytes[] = {0x83, 0x94, 0xc8, 0xf0, - 0x3e, 0x51, 0x57, 0x08}; - char new_connection_id_bytes[] = {0xf0, 0x67, 0xa5, 0x50, - 0x2a, 0x42, 0x62, 0xb5}; - char retry_token_bytes[] = {0x74, 0x6f, 0x6b, 0x65, 0x6e}; + uint8_t original_connection_id_bytes[] = {0x83, 0x94, 0xc8, 0xf0, + 0x3e, 0x51, 0x57, 0x08}; + uint8_t new_connection_id_bytes[] = {0xf0, 0x67, 0xa5, 0x50, + 0x2a, 0x42, 0x62, 0xb5}; + uint8_t retry_token_bytes[] = {0x74, 0x6f, 0x6b, 0x65, 0x6e}; QuicConnectionId original_connection_id( - original_connection_id_bytes, + reinterpret_cast<char*>(original_connection_id_bytes), ABSL_ARRAYSIZE(original_connection_id_bytes)); - QuicConnectionId new_connection_id(new_connection_id_bytes, - ABSL_ARRAYSIZE(new_connection_id_bytes)); + QuicConnectionId new_connection_id( + reinterpret_cast<char*>(new_connection_id_bytes), + ABSL_ARRAYSIZE(new_connection_id_bytes)); - std::string retry_token(retry_token_bytes, ABSL_ARRAYSIZE(retry_token_bytes)); + std::string retry_token(reinterpret_cast<char*>(retry_token_bytes), + ABSL_ARRAYSIZE(retry_token_bytes)); if (invalid_retry_tag) { // Flip the last bit of the retry packet to prevent the integrity tag @@ -10611,7 +10613,8 @@ // Process the RETRY packet. connection_.ProcessUdpPacket( kSelfAddress, kPeerAddress, - QuicReceivedPacket(retry_packet, retry_packet_length, clock_.Now())); + QuicReceivedPacket(reinterpret_cast<char*>(retry_packet), + retry_packet_length, clock_.Now())); if (invalid_retry_tag) { // Make sure we refuse to process a RETRY with invalid tag.
diff --git a/quic/core/quic_dispatcher_test.cc b/quic/core/quic_dispatcher_test.cc index 5a7a709..3a98be3 100644 --- a/quic/core/quic_dispatcher_test.cc +++ b/quic/core/quic_dispatcher_test.cc
@@ -924,10 +924,12 @@ QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); CreateTimeWaitListManager(); - char short_packet[21] = {0x70, 0xa7, 0x02, 0x6b}; - QuicReceivedPacket packet(short_packet, 21, QuicTime::Zero()); - char valid_size_packet[23] = {0x70, 0xa7, 0x02, 0x6c}; - QuicReceivedPacket packet2(valid_size_packet, 23, QuicTime::Zero()); + uint8_t short_packet[21] = {0x70, 0xa7, 0x02, 0x6b}; + QuicReceivedPacket packet(reinterpret_cast<char*>(short_packet), 21, + QuicTime::Zero()); + uint8_t valid_size_packet[23] = {0x70, 0xa7, 0x02, 0x6c}; + QuicReceivedPacket packet2(reinterpret_cast<char*>(valid_size_packet), 23, + QuicTime::Zero()); EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0); EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _, _)) .Times(0); @@ -1186,10 +1188,10 @@ RejectDeprecatedVersionDraft28WithVersionNegotiation) { QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); CreateTimeWaitListManager(); - char packet[kMinPacketSizeForVersionNegotiation] = { + uint8_t packet[kMinPacketSizeForVersionNegotiation] = { 0xC0, 0xFF, 0x00, 0x00, 28, /*destination connection ID length*/ 0x08}; - QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet), - QuicTime::Zero()); + QuicReceivedPacket received_packet(reinterpret_cast<char*>(packet), + ABSL_ARRAYSIZE(packet), QuicTime::Zero()); EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0); EXPECT_CALL( *time_wait_list_manager_, @@ -1203,10 +1205,10 @@ RejectDeprecatedVersionDraft27WithVersionNegotiation) { QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); CreateTimeWaitListManager(); - char packet[kMinPacketSizeForVersionNegotiation] = { + uint8_t packet[kMinPacketSizeForVersionNegotiation] = { 0xC0, 0xFF, 0x00, 0x00, 27, /*destination connection ID length*/ 0x08}; - QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet), - QuicTime::Zero()); + QuicReceivedPacket received_packet(reinterpret_cast<char*>(packet), + ABSL_ARRAYSIZE(packet), QuicTime::Zero()); EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0); EXPECT_CALL( *time_wait_list_manager_, @@ -1220,10 +1222,10 @@ RejectDeprecatedVersionDraft25WithVersionNegotiation) { QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); CreateTimeWaitListManager(); - char packet[kMinPacketSizeForVersionNegotiation] = { + uint8_t packet[kMinPacketSizeForVersionNegotiation] = { 0xC0, 0xFF, 0x00, 0x00, 25, /*destination connection ID length*/ 0x08}; - QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet), - QuicTime::Zero()); + QuicReceivedPacket received_packet(reinterpret_cast<char*>(packet), + ABSL_ARRAYSIZE(packet), QuicTime::Zero()); EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0); EXPECT_CALL( *time_wait_list_manager_, @@ -1237,10 +1239,10 @@ RejectDeprecatedVersionT050WithVersionNegotiation) { QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); CreateTimeWaitListManager(); - char packet[kMinPacketSizeForVersionNegotiation] = { + uint8_t packet[kMinPacketSizeForVersionNegotiation] = { 0xC0, 'T', '0', '5', '0', /*destination connection ID length*/ 0x08}; - QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet), - QuicTime::Zero()); + QuicReceivedPacket received_packet(reinterpret_cast<char*>(packet), + ABSL_ARRAYSIZE(packet), QuicTime::Zero()); EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0); EXPECT_CALL( *time_wait_list_manager_, @@ -1254,10 +1256,10 @@ RejectDeprecatedVersionQ049WithVersionNegotiation) { QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); CreateTimeWaitListManager(); - char packet[kMinPacketSizeForVersionNegotiation] = { + uint8_t packet[kMinPacketSizeForVersionNegotiation] = { 0xC0, 'Q', '0', '4', '9', /*destination connection ID length*/ 0x08}; - QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet), - QuicTime::Zero()); + QuicReceivedPacket received_packet(reinterpret_cast<char*>(packet), + ABSL_ARRAYSIZE(packet), QuicTime::Zero()); EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0); EXPECT_CALL( *time_wait_list_manager_, @@ -1271,10 +1273,10 @@ RejectDeprecatedVersionQ048WithVersionNegotiation) { QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); CreateTimeWaitListManager(); - char packet[kMinPacketSizeForVersionNegotiation] = { + uint8_t packet[kMinPacketSizeForVersionNegotiation] = { 0xC0, 'Q', '0', '4', '8', /*connection ID length byte*/ 0x50}; - QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet), - QuicTime::Zero()); + QuicReceivedPacket received_packet(reinterpret_cast<char*>(packet), + ABSL_ARRAYSIZE(packet), QuicTime::Zero()); EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0); EXPECT_CALL( *time_wait_list_manager_, @@ -1288,10 +1290,10 @@ RejectDeprecatedVersionQ047WithVersionNegotiation) { QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); CreateTimeWaitListManager(); - char packet[kMinPacketSizeForVersionNegotiation] = { + uint8_t packet[kMinPacketSizeForVersionNegotiation] = { 0xC0, 'Q', '0', '4', '7', /*connection ID length byte*/ 0x50}; - QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet), - QuicTime::Zero()); + QuicReceivedPacket received_packet(reinterpret_cast<char*>(packet), + ABSL_ARRAYSIZE(packet), QuicTime::Zero()); EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0); EXPECT_CALL( *time_wait_list_manager_, @@ -1305,10 +1307,10 @@ RejectDeprecatedVersionQ045WithVersionNegotiation) { QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); CreateTimeWaitListManager(); - char packet[kMinPacketSizeForVersionNegotiation] = { + uint8_t packet[kMinPacketSizeForVersionNegotiation] = { 0xC0, 'Q', '0', '4', '5', /*connection ID length byte*/ 0x50}; - QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet), - QuicTime::Zero()); + QuicReceivedPacket received_packet(reinterpret_cast<char*>(packet), + ABSL_ARRAYSIZE(packet), QuicTime::Zero()); EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0); EXPECT_CALL( *time_wait_list_manager_, @@ -1322,10 +1324,11 @@ RejectDeprecatedVersionQ044WithVersionNegotiation) { QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); CreateTimeWaitListManager(); - char packet44[kMinPacketSizeForVersionNegotiation] = { + uint8_t packet44[kMinPacketSizeForVersionNegotiation] = { 0xFF, 'Q', '0', '4', '4', /*connection ID length byte*/ 0x50}; - QuicReceivedPacket received_packet44( - packet44, kMinPacketSizeForVersionNegotiation, QuicTime::Zero()); + QuicReceivedPacket received_packet44(reinterpret_cast<char*>(packet44), + kMinPacketSizeForVersionNegotiation, + QuicTime::Zero()); EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0); EXPECT_CALL( *time_wait_list_manager_, @@ -1549,7 +1552,7 @@ EXPECT_CALL(*time_wait_list_manager_, SendPacket(_, _, _)).Times(0); // clang-format off - char coalesced_packet[1200] = { + uint8_t coalesced_packet[1200] = { // first coalesced packet // public flags (long header with packet type INITIAL and // 4-byte packet number) @@ -1586,7 +1589,8 @@ 0x12, 0x34, 0x56, 0x79, }; // clang-format on - QuicReceivedPacket packet(coalesced_packet, 1200, QuicTime::Zero()); + QuicReceivedPacket packet(reinterpret_cast<char*>(coalesced_packet), 1200, + QuicTime::Zero()); dispatcher_->ProcessPacket(server_address_, client_address, packet); }
diff --git a/quic/core/quic_framer_test.cc b/quic/core/quic_framer_test.cc index 63a1ad5..edc4ace 100644 --- a/quic/core/quic_framer_test.cc +++ b/quic/core/quic_framer_test.cc
@@ -61,9 +61,10 @@ } QuicConnectionId FramerTestConnectionIdNineBytes() { - char connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, - 0x54, 0x32, 0x10, 0x42}; - return QuicConnectionId(connection_id_bytes, sizeof(connection_id_bytes)); + uint8_t connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, + 0x54, 0x32, 0x10, 0x42}; + return QuicConnectionId(reinterpret_cast<char*>(connection_id_bytes), + sizeof(connection_id_bytes)); } const QuicPacketNumber kPacketNumber = QuicPacketNumber(UINT64_C(0x12345678)); @@ -13730,9 +13731,9 @@ return; } SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); - char connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, - 0x54, 0x32, 0x10, 0x42}; - QuicConnectionId connection_id(connection_id_bytes, + uint8_t connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, + 0x54, 0x32, 0x10, 0x42}; + QuicConnectionId connection_id(reinterpret_cast<char*>(connection_id_bytes), sizeof(connection_id_bytes)); QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); QuicFramerPeer::SetExpectedServerConnectionIDLength(&framer_, @@ -14031,7 +14032,7 @@ TEST_P(QuicFramerTest, WriteClientVersionNegotiationProbePacket) { // clang-format off - static const char expected_packet[1200] = { + static const uint8_t expected_packet[1200] = { // IETF long header with fixed bit set, type initial, all-0 encrypted bits. 0xc0, // Version, part of the IETF space reserved for negotiation. @@ -14080,9 +14081,9 @@ EXPECT_TRUE(QuicFramer::WriteClientVersionNegotiationProbePacket( packet, sizeof(packet), destination_connection_id_bytes, sizeof(destination_connection_id_bytes))); - quiche::test::CompareCharArraysWithHexError("constructed packet", packet, - sizeof(packet), expected_packet, - sizeof(expected_packet)); + quiche::test::CompareCharArraysWithHexError( + "constructed packet", packet, sizeof(packet), + reinterpret_cast<const char*>(expected_packet), sizeof(expected_packet)); QuicEncryptedPacket encrypted(reinterpret_cast<const char*>(packet), sizeof(packet), false); if (!framer_.version().HasLengthPrefixedConnectionIds()) { @@ -14102,7 +14103,7 @@ TEST_P(QuicFramerTest, DispatcherParseOldClientVersionNegotiationProbePacket) { // clang-format off - static const char packet[1200] = { + static const uint8_t packet[1200] = { // IETF long header with fixed bit set, type initial, all-0 encrypted bits. 0xc0, // Version, part of the IETF space reserved for negotiation. @@ -14179,7 +14180,7 @@ TEST_P(QuicFramerTest, DispatcherParseClientVersionNegotiationProbePacket) { // clang-format off - static const char packet[1200] = { + static const uint8_t packet[1200] = { // IETF long header with fixed bit set, type initial, all-0 encrypted bits. 0xc0, // Version, part of the IETF space reserved for negotiation. @@ -14257,7 +14258,7 @@ TEST_P(QuicFramerTest, ParseServerVersionNegotiationProbeResponse) { // clang-format off - const char packet[] = { + const uint8_t packet[] = { // IETF long header with fixed bit set, type initial, all-0 encrypted bits. 0xc0, // Version of 0, indicating version negotiation.