From d9d0d1d1a2e7b1380cb5ea05268f9c1cf6e2b13d Mon Sep 17 00:00:00 2001
From: fakeshadow <24548779@qq.com>
Date: Wed, 10 Feb 2021 15:11:12 -0800
Subject: [PATCH] reduce unsafe (#1972)
---
actix-http/src/h1/dispatcher.rs | 7 +-
actix-http/src/ws/frame.rs | 12 +-
actix-http/src/ws/mask.rs | 189 ++++++++++++--------------------
3 files changed, 77 insertions(+), 131 deletions(-)
diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs
index 1d28a0a3..3882c2d5 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 8c49524e..78d487dd 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