Skip to content

Commit

Permalink
do not round-trip function pointer through integer
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Apr 7, 2022
1 parent fe85591 commit c599a4c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions library/std/src/sys/windows/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ macro_rules! compat_fn {
let symbol_name: *const u8 = concat!(stringify!($symbol), "\0").as_ptr();
let module_handle = $crate::sys::c::GetModuleHandleA(module_name as *const i8);
if !module_handle.is_null() {
match $crate::sys::c::GetProcAddress(module_handle, symbol_name as *const i8).addr() {
0 => {}
n => {
return Some(mem::transmute::<usize, F>(n));
}
let ptr = $crate::sys::c::GetProcAddress(module_handle, symbol_name as *const i8);
if !ptr.is_null() {
// Transmute to the right function pointer type.
return Some(mem::transmute(ptr));
}
}
return None;
Expand Down

0 comments on commit c599a4c

Please sign in to comment.