diff options
author | Sunil Nimmagadda <sunil@nimmagadda.net> | 2025-07-01 11:47:29 +0530 |
---|---|---|
committer | Sunil Nimmagadda <sunil@nimmagadda.net> | 2025-07-01 11:47:29 +0530 |
commit | 102c0555bac8449263af1ecff40d32acba436f67 (patch) | |
tree | 59570a7b442d04dd44b55cd9542189de723e4ed8 /src | |
parent | 07636c179cc7b404d3b9d14c01490188b3052331 (diff) |
Simplify buffer size calulations.
Split up fixed and dynamic parts and add them up for the final size.
Diffstat (limited to 'src')
-rw-r--r-- | src/vrrpv2.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/vrrpv2.rs b/src/vrrpv2.rs index 9a8fc95..2277dd2 100644 --- a/src/vrrpv2.rs +++ b/src/vrrpv2.rs @@ -100,8 +100,8 @@ impl<T: AsRef<[u8]>> BytesReader for Cursor<T> { impl VRRPv2 { pub fn to_bytes(&self) -> Result<Vec<u8>, std::io::Error> { - let sz = (4 + self.count_ip_addrs) * 4; - let bytes: Vec<u8> = Vec::with_capacity(sz.into()); + let sz = 16 + (self.ip_addrs.len() * 4); + let bytes: Vec<u8> = Vec::with_capacity(sz); let mut wr = Cursor::new(bytes); wr.write_all( [ |