Merge pull request #37 from bluetech/ununsafe

frame: eliminate an unsafe when reading message data into the buffer
pull/44/head
Alexey Galakhov 7 years ago committed by GitHub
commit 59d7012702
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/protocol/frame/frame.rs

@ -5,7 +5,6 @@ use std::default::Default;
use std::string::{String, FromUtf8Error}; use std::string::{String, FromUtf8Error};
use std::result::Result as StdResult; use std::result::Result as StdResult;
use byteorder::{ByteOrder, ReadBytesExt, WriteBytesExt, NetworkEndian}; use byteorder::{ByteOrder, ReadBytesExt, WriteBytesExt, NetworkEndian};
use bytes::BufMut;
use error::{Error, Result}; use error::{Error, Result};
use super::coding::{OpCode, Control, Data, CloseCode}; use super::coding::{OpCode, Control, Data, CloseCode};
@ -363,11 +362,9 @@ impl Frame {
// Size is checked above, so it won't be truncated here. // Size is checked above, so it won't be truncated here.
let mut data = Vec::with_capacity(length as usize); let mut data = Vec::with_capacity(length as usize);
if length > 0 { if length > 0 {
unsafe { try!(cursor.take(length).read_to_end(&mut data));
try!(cursor.read_exact(data.bytes_mut()));
data.advance_mut(length as usize);
}
} }
debug_assert_eq!(data.len() as u64, length);
let frame = Frame { let frame = Frame {
finished: finished, finished: finished,

Loading…
Cancel
Save