From c599a4cfc3e33903d6523ba7355f862780714bda Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 7 Apr 2022 14:58:02 -0400 Subject: [PATCH] do not round-trip function pointer through integer --- library/std/src/sys/windows/compat.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/library/std/src/sys/windows/compat.rs b/library/std/src/sys/windows/compat.rs index b6f2f894de8ec..c55df04200313 100644 --- a/library/std/src/sys/windows/compat.rs +++ b/library/std/src/sys/windows/compat.rs @@ -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::(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;