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.
try_from
1 parent 525f90c commit 0c648c8Copy full SHA for 0c648c8
src/protocol/frame.rs
@@ -42,11 +42,10 @@ 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 = match usize::try_from(len.0) {
+ Ok(n) => n,
+ Err(_) => return Err(ReadError::NegativeMessageSize { size: len.0 }),
+ };
50
51
// check max message size to not blow up memory
52
if len > max_message_size {
0 commit comments