Add -Wtype-limits to QUIC
This removes comparisons that the compiler believes are guaranteed to always have the same outcome. To ensure the compile-time property is always there I've added static_asserts().
gfe-relnote: n/a, compile-only
PiperOrigin-RevId: 253692720
Change-Id: I17602bcd9e20abb19f7e84109a67a40b559bbbf6
diff --git a/quic/core/quic_framer.cc b/quic/core/quic_framer.cc
index 1aec0bf..6446ef8 100644
--- a/quic/core/quic_framer.cc
+++ b/quic/core/quic_framer.cc
@@ -4937,8 +4937,12 @@
return false;
}
if (!no_stream_frame_length) {
- if ((frame.data_length > std::numeric_limits<uint16_t>::max()) ||
- !writer->WriteUInt16(static_cast<uint16_t>(frame.data_length))) {
+ static_assert(
+ std::numeric_limits<typeof(frame.data_length)>::max() <=
+ std::numeric_limits<uint16_t>::max(),
+ "If frame.data_length can hold more than a uint16_t than we need to "
+ "check that frame.data_length <= std::numeric_limits<uint16_t>::max()");
+ if (!writer->WriteUInt16(static_cast<uint16_t>(frame.data_length))) {
QUIC_BUG << "Writing stream frame length failed";
return false;
}