On 7/3/25 15:46, Stefan Hanreich wrote:
> On 7/3/25 15:11, Wolfgang Bumiller wrote:
>>> +    /// checks whether this CIDR contains an IPv4 address.
>>> +    pub fn contains_address(&self, other: &Ipv4Addr) -> bool {
>>> +        let bits = u32::from_be_bytes(self.addr.octets());
>>> +        let other_bits = u32::from_be_bytes(other.octets());
>>> +
>>> +        let shift_amount: u32 = 
>>> IPV4_LENGTH.saturating_sub(self.mask).into();
>>> +
>>> +        bits.checked_shr(shift_amount).unwrap_or(0)
>>> +            == other_bits.checked_shr(shift_amount).unwrap_or(0)
>>
>> ^ Could IMO just use `>>` since `IPV4_LENGTH.saturating_sub(self.mask)`
>> is always <= the number of bits or an u32.
> 
> shift_amount can be 32 and >> needs the shift amount to be strictly
> smaller than the width of the integer, see [1].
> 
> We could short-circuit when mask == width instead?

mask == 0, ofc


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to