@@ -486,6 +486,7 @@ impl<'a> Socket<'a> {
486
486
// [...] the above constraints imply that 2 * the max window size must be less
487
487
// than 2**31 [...] Thus, the shift count must be limited to 14 (which allows
488
488
// windows of 2**30 = 1 Gbyte).
489
+ #[ cfg( not( target_pointer_width = "16" ) ) ] // Prevent overflow
489
490
if rx_capacity > ( 1 << 30 ) {
490
491
panic ! ( "receiving buffer too large, cannot exceed 1 GiB" )
491
492
}
@@ -592,10 +593,7 @@ impl<'a> Socket<'a> {
592
593
///
593
594
#[ inline]
594
595
fn scaled_window ( & self ) -> u16 {
595
- cmp:: min (
596
- self . rx_buffer . window ( ) >> self . remote_win_shift as usize ,
597
- ( 1 << 16 ) - 1 ,
598
- ) as u16
596
+ u16:: try_from ( self . rx_buffer . window ( ) >> self . remote_win_shift as usize ) . unwrap_or ( u16:: MAX )
599
597
}
600
598
601
599
/// Set the timeout duration.
@@ -1868,7 +1866,10 @@ impl<'a> Socket<'a> {
1868
1866
let assembler_was_empty = self . assembler . is_empty ( ) ;
1869
1867
1870
1868
// Try adding payload octets to the assembler.
1871
- let Ok ( contig_len) = self . assembler . add_then_remove_front ( payload_offset, payload_len) else {
1869
+ let Ok ( contig_len) = self
1870
+ . assembler
1871
+ . add_then_remove_front ( payload_offset, payload_len)
1872
+ else {
1872
1873
net_debug ! (
1873
1874
"assembler: too many holes to add {} octets at offset {}" ,
1874
1875
payload_len,
@@ -2155,7 +2156,7 @@ impl<'a> Socket<'a> {
2155
2156
State :: SynSent | State :: SynReceived => {
2156
2157
repr. control = TcpControl :: Syn ;
2157
2158
// window len must NOT be scaled in SYNs.
2158
- repr. window_len = self . rx_buffer . window ( ) . min ( ( 1 << 16 ) - 1 ) as u16 ;
2159
+ repr. window_len = u16 :: try_from ( self . rx_buffer . window ( ) ) . unwrap_or ( u16:: MAX ) ;
2159
2160
if self . state == State :: SynSent {
2160
2161
repr. ack_number = None ;
2161
2162
repr. window_scale = Some ( self . remote_win_shift ) ;
0 commit comments