From 5b7aed101a39232a11a62519af1422cb7954027f Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 6 Jul 2018 13:54:43 +0600 Subject: [PATCH] remove unsafe --- src/ws/frame.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ws/frame.rs b/src/ws/frame.rs index f71564e82..70065774b 100644 --- a/src/ws/frame.rs +++ b/src/ws/frame.rs @@ -260,15 +260,14 @@ impl Frame { } // unmask - if let Some(mask) = mask { - // Unsafe: request body stream is owned by WsStream. only one ref to - // bytes exists. Bytes object get freezed in continuous non-overlapping blocks - let p: &mut [u8] = unsafe { - let ptr: &[u8] = &data; - &mut *(ptr as *const _ as *mut _) - }; - apply_mask(p, mask); - } + let data = if let Some(mask) = mask { + let mut buf = BytesMut::new(); + buf.extend_from_slice(&data); + apply_mask(&mut buf, mask); + buf.freeze() + } else { + data + }; Ok(Async::Ready(Some(Frame { finished,