From 102c0555bac8449263af1ecff40d32acba436f67 Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Tue, 1 Jul 2025 11:47:29 +0530 Subject: Simplify buffer size calulations. Split up fixed and dynamic parts and add them up for the final size. --- src/vrrpv2.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') 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> BytesReader for Cursor { impl VRRPv2 { pub fn to_bytes(&self) -> Result, std::io::Error> { - let sz = (4 + self.count_ip_addrs) * 4; - let bytes: Vec = Vec::with_capacity(sz.into()); + let sz = 16 + (self.ip_addrs.len() * 4); + let bytes: Vec = Vec::with_capacity(sz); let mut wr = Cursor::new(bytes); wr.write_all( [ -- cgit v1.2.3