Skip to content

Commit

Permalink
custom: Add check for function type
Browse files Browse the repository at this point in the history
This makes sure we get a good compiler error if we give a bad path.

Signed-off-by: Joe Richey <joerichey@google.com>
  • Loading branch information
josephlr committed Sep 9, 2020
1 parent c8f40e1 commit 8e1ab1a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ macro_rules! register_custom_getrandom {
// We use an extern "C" function to get the guarantees of a stable ABI.
#[no_mangle]
extern "C" fn __getrandom_custom(dest: *mut u8, len: usize) -> u32 {
let f: fn(&mut [u8]) -> Result<(), ::getrandom::Error> = $path;
let slice = unsafe { ::core::slice::from_raw_parts_mut(dest, len) };
match $path(slice) {
match f(slice) {
Ok(()) => 0,
Err(e) => e.code().get(),
}
Expand Down

0 comments on commit 8e1ab1a

Please sign in to comment.