We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents cf0358e + 7dc2e9e commit a090364Copy full SHA for a090364
src/protocol/frame.rs
@@ -42,11 +42,8 @@ where
42
let len = Int32::read(&mut Cursor::new(len_buf))
43
.expect("Reading Int32 from in-mem buffer should always work");
44
45
- // convert to usize
46
- if len.0 < 0 {
47
- return Err(ReadError::NegativeMessageSize { size: len.0 });
48
- }
49
- let len = len.0 as usize;
+ let len =
+ usize::try_from(len.0).map_err(|_| ReadError::NegativeMessageSize { size: len.0 })?;
50
51
// check max message size to not blow up memory
52
if len > max_message_size {
@@ -70,7 +67,7 @@ where
70
67
});
71
68
}
72
69
73
- let mut buf = vec![0u8; len as usize];
+ let mut buf = vec![0u8; len];
74
self.read_exact(&mut buf).await?;
75
Ok(buf)
76
0 commit comments