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

Fix miri error #640

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,19 @@ jobs:

- name: Check
run: cargo check --target wasm32-unknown-unknown

miri:
name: Miri
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Rust
uses: dtolnay/rust-toolchain@nightly
with:
components: miri

- name: Test
run: MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo miri test
8 changes: 4 additions & 4 deletions src/header/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2108,22 +2108,22 @@ impl<'a, T> IterMut<'a, T> {
self.cursor = Some(Cursor::Head);
}

let entry = unsafe { &mut (*self.map).entries[self.entry] };
let entry = unsafe { &(*self.map).entries[self.entry] };

match self.cursor.unwrap() {
Head => {
self.cursor = entry.links.map(|l| Values(l.next));
Some((&entry.key, &mut entry.value as *mut _))
Some((&entry.key, &entry.value as *const _ as *mut _))
}
Values(idx) => {
let extra = unsafe { &mut (*self.map).extra_values[idx] };
let extra = unsafe { &(*self.map).extra_values[idx] };

match extra.next {
Link::Entry(_) => self.cursor = None,
Link::Extra(i) => self.cursor = Some(Values(i)),
}

Some((&entry.key, &mut extra.value as *mut _))
Some((&entry.key, &extra.value as *const _ as *mut _))
}
}
}
Expand Down
20 changes: 16 additions & 4 deletions tests/header_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn drain_entry() {
assert_eq!(vals[1], "world2");
}

assert_eq!(5-2+1, headers.len());
assert_eq!(5 - 2 + 1, headers.len());
}

#[test]
Expand Down Expand Up @@ -427,7 +427,6 @@ fn value_htab() {
HeaderValue::from_str("hello\tworld").unwrap();
}


#[test]
fn remove_multiple_a() {
let mut headers = HeaderMap::new();
Expand Down Expand Up @@ -570,7 +569,8 @@ fn remove_entry_multi_3_others() {
}

fn remove_all_values<K>(headers: &mut HeaderMap, key: K) -> Vec<HeaderValue>
where K: IntoHeaderName
where
K: IntoHeaderName,
{
match headers.entry(key) {
Entry::Occupied(e) => e.remove_entry_mult().1.collect(),
Expand Down Expand Up @@ -629,10 +629,22 @@ fn remove_entry_3_others_b() {
}

fn remove_values<K>(headers: &mut HeaderMap, key: K) -> Option<HeaderValue>
where K: IntoHeaderName
where
K: IntoHeaderName,
{
match headers.entry(key) {
Entry::Occupied(e) => Some(e.remove_entry().1),
Entry::Vacant(_) => None,
}
}

#[test]
fn ensure_miri_sharedreadonly_not_violated() {
let mut headers = HeaderMap::new();
headers.insert(
HeaderName::from_static("chunky-trailer"),
HeaderValue::from_static("header data"),
);

let _foo = &headers.iter().next();
}
Loading