Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(http1): Replace usage of mem::uninitialized with MaybeUninit #2536

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/proto/h1/role.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
// `mem::uninitialized` replaced with `mem::MaybeUninit`,
// can't upgrade yet
#![allow(deprecated)]

use std::fmt::{self, Write};
use std::mem;
use std::mem::{self, MaybeUninit};

#[cfg(any(test, feature = "server", feature = "ffi"))]
use bytes::Bytes;
use bytes::BytesMut;
use http::header::{self, Entry, HeaderName, HeaderValue};
#[cfg(feature = "server")]
use http::header::ValueIter;
use http::header::{self, Entry, HeaderName, HeaderValue};
use http::{HeaderMap, Method, StatusCode, Version};

use crate::body::DecodedLength;
Expand Down Expand Up @@ -126,9 +122,11 @@ impl Http1Transaction for Server {
// but we *never* read any of it until after httparse has assigned
// values into it. By not zeroing out the stack memory, this saves
// a good ~5% on pipeline benchmarks.
let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::uninitialized() };
let mut headers_indices: [HeaderIndices; MAX_HEADERS] =
unsafe { MaybeUninit::uninit().assume_init() };
{
let mut headers: [httparse::Header<'_>; MAX_HEADERS] = unsafe { mem::uninitialized() };
let mut headers: [httparse::Header<'_>; MAX_HEADERS] =
unsafe { MaybeUninit::uninit().assume_init() };
trace!(
"Request.parse([Header; {}], [u8; {}])",
headers.len(),
Expand Down Expand Up @@ -880,19 +878,19 @@ impl Http1Transaction for Client {
// Loop to skip information status code headers (100 Continue, etc).
loop {
// Unsafe: see comment in Server Http1Transaction, above.
let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::uninitialized() };
let mut headers_indices: [HeaderIndices; MAX_HEADERS] =
unsafe { MaybeUninit::uninit().assume_init() };
let (len, status, reason, version, headers_len) = {
let mut headers: [httparse::Header<'_>; MAX_HEADERS] =
unsafe { mem::uninitialized() };
unsafe { MaybeUninit::uninit().assume_init() };
trace!(
"Response.parse([Header; {}], [u8; {}])",
headers.len(),
buf.len()
);
let mut res = httparse::Response::new(&mut headers);
let bytes = buf.as_ref();
match ctx.h1_parser_config.parse_response(&mut res, bytes)
{
match ctx.h1_parser_config.parse_response(&mut res, bytes) {
Ok(httparse::Status::Complete(len)) => {
trace!("Response.parse Complete({})", len);
let status = StatusCode::from_u16(res.code.unwrap())?;
Expand Down