File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -913,11 +913,18 @@ impl Endpoint {
913913 /// We leave some space unused so that `new_cid` can be relied upon to finish quickly. We don't
914914 /// bother to check when CID longer than 4 bytes are used because 2^40 connections is a lot.
915915 fn cids_exhausted ( & self ) -> bool {
916- self . local_cid_generator . cid_len ( ) <= 4
917- && self . local_cid_generator . cid_len ( ) != 0
918- && ( 2usize . pow ( self . local_cid_generator . cid_len ( ) as u32 * 8 )
919- - self . index . connection_ids . len ( ) )
920- < 2usize . pow ( self . local_cid_generator . cid_len ( ) as u32 * 8 - 2 )
916+ let cid_len = self . local_cid_generator . cid_len ( ) ;
917+ if cid_len == 0 || cid_len > 4 {
918+ return false ;
919+ }
920+
921+ // Keep this architecture-independent: on 32-bit targets, 2usize.pow(32) overflows.
922+ let bits = ( cid_len * 8 ) as u32 ;
923+ let space = 1u64 << bits;
924+ let reserve = 1u64 << ( bits - 2 ) ;
925+ let len = self . index . connection_ids . len ( ) as u64 ;
926+
927+ len > ( space - reserve)
921928 }
922929}
923930
You can’t perform that action at this time.
0 commit comments