Skip to content

Commit c599a4c

Browse files
committed
do not round-trip function pointer through integer
1 parent fe85591 commit c599a4c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

library/std/src/sys/windows/compat.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ macro_rules! compat_fn {
9292
let symbol_name: *const u8 = concat!(stringify!($symbol), "\0").as_ptr();
9393
let module_handle = $crate::sys::c::GetModuleHandleA(module_name as *const i8);
9494
if !module_handle.is_null() {
95-
match $crate::sys::c::GetProcAddress(module_handle, symbol_name as *const i8).addr() {
96-
0 => {}
97-
n => {
98-
return Some(mem::transmute::<usize, F>(n));
99-
}
95+
let ptr = $crate::sys::c::GetProcAddress(module_handle, symbol_name as *const i8);
96+
if !ptr.is_null() {
97+
// Transmute to the right function pointer type.
98+
return Some(mem::transmute(ptr));
10099
}
101100
}
102101
return None;

0 commit comments

Comments
 (0)