From 47c6d3b4295ef4eeda41fc44b6801f4319af5013 Mon Sep 17 00:00:00 2001
From: fakeshadow <24548779@qq.com>
Date: Tue, 9 Feb 2021 16:48:27 -0800
Subject: [PATCH] reduce unsafe
---
actix-http/src/h1/dispatcher.rs | 7 +-
actix-http/src/ws/frame.rs | 12 ++-
actix-http/src/ws/mask.rs | 183 +++++++++++---------------------
3 files changed, 71 insertions(+), 131 deletions(-)
diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs
index 8fbf3ede0..7bc8b491c 100644
--- a/actix-http/src/h1/dispatcher.rs
+++ b/actix-http/src/h1/dispatcher.rs
@@ -309,11 +309,8 @@ where
}
}
- // SAFETY: setting length to 0 is safe
- // skips one length check vs truncate
- unsafe {
- write_buf.set_len(0);
- }
+ // everything has written to io. clear buffer.
+ write_buf.clear();
// flush the io and check if get blocked.
let blocked = io.poll_flush(cx)?.is_pending();
diff --git a/actix-http/src/ws/frame.rs b/actix-http/src/ws/frame.rs
index 8c49524e6..78d487dd2 100644
--- a/actix-http/src/ws/frame.rs
+++ b/actix-http/src/ws/frame.rs
@@ -16,7 +16,8 @@ impl Parser {
src: &[u8],
server: bool,
max_size: usize,
- ) -> Result