From cbb80df31146ae0e258b545edd6ddd2494fafcfa Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 22 Mar 2020 18:16:36 -0700 Subject: [PATCH] the size of the command pkt was overflowing urwejrfklweqjflkqw --- psopacket/src/lib.rs | 2 +- src/lib.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/psopacket/src/lib.rs b/psopacket/src/lib.rs index 9e8df70..27f897a 100644 --- a/psopacket/src/lib.rs +++ b/psopacket/src/lib.rs @@ -447,7 +447,7 @@ fn generate_psomessage_impl(msg_cmd: u8, name: syn::Ident, attrs: &Vec let mut fullbuf = Vec::new(); fullbuf.push(#msg_cmd); - fullbuf.push((buf.len() as u8 + 2) / 4); + fullbuf.push(((buf.len() + 2) / 4) as u8); fullbuf.extend_from_slice(&mut buf); fullbuf diff --git a/src/lib.rs b/src/lib.rs index 0b5e266..20409b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -528,4 +528,21 @@ mod test { c: 5, }); } + + #[test] + fn test_pso_message_overflow() { + #[pso_message(0x23)] + struct Test { + b: [u32; 100], + }; + + let test = Test { + client: 1, + target: 2, + b: [23; 100], + }; + + let bytes = test.as_bytes(); + assert!(bytes[1] == 101); + } }