Skip to content

Commit

Permalink
Web: use safe method to copy to MaybeUninit (#584)
Browse files Browse the repository at this point in the history
This removes the last `unsafe` call in the Web implementation.
See
[`Uint8Array::copy_to_uninit`](https://docs.rs/js-sys/0.3.77/js_sys/struct.Uint8Array.html#method.copy_to_uninit).
  • Loading branch information
daxpedda authored Jan 14, 2025
1 parent 2648e60 commit 6be4012
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ windows-targets = "0.52"
[target.'cfg(all(getrandom_backend = "wasm_js", target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dependencies]
wasm-bindgen = { version = "0.2.98", default-features = false }
[target.'cfg(all(getrandom_backend = "wasm_js", target_arch = "wasm32", any(target_os = "unknown", target_os = "none"), target_feature = "atomics"))'.dependencies]
js-sys = { version = "0.3.75", default-features = false }
js-sys = { version = "0.3.77", default-features = false }
[target.'cfg(all(getrandom_backend = "wasm_js", target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dev-dependencies]
wasm-bindgen-test = "0.3"

Expand Down
3 changes: 1 addition & 2 deletions src/backends/wasm_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
return Err(Error::WEB_CRYPTO);
}

// SAFETY: `sub_buf`'s length is the same length as `chunk`
unsafe { sub_buf.raw_copy_to_ptr(chunk.as_mut_ptr().cast::<u8>()) };
sub_buf.copy_to_uninit(chunk);
}
Ok(())
}
Expand Down

0 comments on commit 6be4012

Please sign in to comment.