Skip to content

Commit

Permalink
Unrolled build for rust-lang#123798
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#123798 - tniessen:patch-1, r=workingjubilee

Avoid invalid socket address in length calculation

This has no effect on the lengths of these constants, but since the IP address portion of the socket addresses was intentionally chosen to be the largest valid value, it seems appropriate to also use the largest valid value for the other components (as opposed to invalid values exceeding the possible ranges).
  • Loading branch information
rust-timer committed Apr 12, 2024
2 parents 616a8f8 + e1972c0 commit fa0411b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/core/src/net/socket_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ impl fmt::Display for SocketAddrV4 {
if f.precision().is_none() && f.width().is_none() {
write!(f, "{}:{}", self.ip(), self.port())
} else {
const LONGEST_IPV4_SOCKET_ADDR: &str = "255.255.255.255:65536";
const LONGEST_IPV4_SOCKET_ADDR: &str = "255.255.255.255:65535";

let mut buf = DisplayBuffer::<{ LONGEST_IPV4_SOCKET_ADDR.len() }>::new();
// Buffer is long enough for the longest possible IPv4 socket address, so this should never fail.
Expand Down Expand Up @@ -621,7 +621,7 @@ impl fmt::Display for SocketAddrV6 {
}
} else {
const LONGEST_IPV6_SOCKET_ADDR: &str =
"[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff%4294967296]:65536";
"[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff%4294967295]:65535";

let mut buf = DisplayBuffer::<{ LONGEST_IPV6_SOCKET_ADDR.len() }>::new();
match self.scope_id() {
Expand Down

0 comments on commit fa0411b

Please sign in to comment.