Skip to content

Commit

Permalink
Use '#[repr(C)]' on 'str' wrappers to guarantee correct layout.
Browse files Browse the repository at this point in the history
Closes #494.
  • Loading branch information
SergioBenitez committed Dec 14, 2017
1 parent 94c7a19 commit 6460be6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/src/http/raw_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use http::uncased::UncasedStr;
///
/// [`FromParam`]: /rocket/request/trait.FromParam.html
/// [`FromFormValue`]: /rocket/request/trait.FromFormValue.html
#[repr(C)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RawStr(str);

Expand Down Expand Up @@ -276,7 +277,7 @@ impl RawStr {
impl<'a> From<&'a str> for &'a RawStr {
#[inline(always)]
fn from(string: &'a str) -> &'a RawStr {
unsafe { ::std::mem::transmute(string) }
unsafe { &*(string as *const str as *const RawStr) }
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/http/uncased.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::fmt;
///
/// let ascii_ref: &UncasedStr = "Hello, world!".into();
/// ```
#[repr(C)]
#[derive(Debug)]
pub struct UncasedStr(str);

Expand Down

0 comments on commit 6460be6

Please sign in to comment.