From: Matt Corallo Date: Thu, 29 Aug 2024 16:45:27 +0000 (+0000) Subject: Use `u64` for `required_unknown_bits_from` indexes, not `usize` X-Git-Tag: v0.0.124-rc1~1^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=1d810a581630491d74d5ee606b15a1ab3f2034b6;p=rust-lightning Use `u64` for `required_unknown_bits_from` indexes, not `usize` While `usize` should be fine, we're multiplying the index by 8 so if we have a jumbo feature bit fitting in a 32-bit size type may not quite work. More importantly, this would be the first use of a `usize` in the public API and dealing with it in bindings is annoying so we just replace with a `u64`. --- diff --git a/lightning-types/src/features.rs b/lightning-types/src/features.rs index a3cb9db2f..5d64a33b3 100644 --- a/lightning-types/src/features.rs +++ b/lightning-types/src/features.rs @@ -911,7 +911,7 @@ impl Features { } /// Returns the set of required features unknown by `other`, as their bit position. - pub fn required_unknown_bits_from(&self, other: &Self) -> Vec { + pub fn required_unknown_bits_from(&self, other: &Self) -> Vec { let mut unknown_bits = Vec::new(); // Bitwise AND-ing with all even bits set except for known features will select required @@ -921,7 +921,7 @@ impl Features { if byte & unknown_features != 0 { for bit in (0..8).step_by(2) { if ((byte & unknown_features) >> bit) & 1 == 1 { - unknown_bits.push(i * 8 + bit); + unknown_bits.push((i as u64) * 8 + bit); } } }