From: Jay Satiro Date: Thu, 28 Dec 2023 00:01:46 +0000 (-0500) Subject: system_win32: fix a function pointer assignment warning X-Git-Tag: curl-8_6_0~166 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=26f002e02ef1142a432c8dc087bd27de71ce38bf;p=thirdparty%2Fcurl.git system_win32: fix a function pointer assignment warning - Use CURLX_FUNCTION_CAST to suppress a function pointer assignment warning. a6bbc87f added lookups of some Windows API functions and then cast them like `*(FARPROC*)&Curl_funcname = address`. Some versions of gcc warn about that as breaking strict-aliasing rules so this PR changes those assignments to use CURLX_FUNCTION_CAST. Bug: https://github.com/curl/curl/pull/12581#issuecomment-1869804317 Reported-by: Marcel Raad Closes https://github.com/curl/curl/pull/12602 --- diff --git a/lib/system_win32.c b/lib/system_win32.c index dd34140d72..d2862de923 100644 --- a/lib/system_win32.c +++ b/lib/system_win32.c @@ -43,21 +43,17 @@ bool Curl_isWindows8OrGreater; /* Handle of iphlpapp.dll */ static HMODULE s_hIpHlpApiDll = NULL; -/* Pointer to the if_nametoindex function */ +/* Function pointers */ IF_NAMETOINDEX_FN Curl_if_nametoindex = NULL; - -void(WSAAPI *Curl_FreeAddrInfoExW)(ADDRINFOEXW_ *pAddrInfoEx) = NULL; -int(WSAAPI *Curl_GetAddrInfoExCancel)(LPHANDLE lpHandle) = NULL; -int(WSAAPI *Curl_GetAddrInfoExW)(PCWSTR pName, PCWSTR pServiceName, - DWORD dwNameSpace, LPGUID lpNspId, const ADDRINFOEXW_ *hints, - ADDRINFOEXW_ **ppResult, struct timeval *timeout, LPOVERLAPPED lpOverlapped, - LOOKUP_COMPLETION lpCompletionRoutine, LPHANDLE lpHandle) = NULL; +FREEADDRINFOEXW_FN Curl_FreeAddrInfoExW = NULL; +GETADDRINFOEXCANCEL_FN Curl_GetAddrInfoExCancel = NULL; +GETADDRINFOEXW_FN Curl_GetAddrInfoExW = NULL; /* Curl_win32_init() performs win32 global initialization */ CURLcode Curl_win32_init(long flags) { #ifdef USE_WINSOCK - HANDLE ws2_32Dll; + HMODULE ws2_32Dll; #endif /* CURL_GLOBAL_WIN32 controls the *optional* part of the initialization which is just for Winsock at the moment. Any required win32 initialization @@ -118,12 +114,12 @@ CURLcode Curl_win32_init(long flags) #ifdef USE_WINSOCK ws2_32Dll = GetModuleHandleA("ws2_32"); if(ws2_32Dll) { - *(FARPROC*)&Curl_FreeAddrInfoExW = GetProcAddress(ws2_32Dll, - "FreeAddrInfoExW"); - *(FARPROC*)&Curl_GetAddrInfoExCancel = GetProcAddress(ws2_32Dll, - "GetAddrInfoExCancel"); - *(FARPROC*)&Curl_GetAddrInfoExW = GetProcAddress(ws2_32Dll, - "GetAddrInfoExW"); + Curl_FreeAddrInfoExW = CURLX_FUNCTION_CAST(FREEADDRINFOEXW_FN, + GetProcAddress(ws2_32Dll, "FreeAddrInfoExW")); + Curl_GetAddrInfoExCancel = CURLX_FUNCTION_CAST(GETADDRINFOEXCANCEL_FN, + GetProcAddress(ws2_32Dll, "GetAddrInfoExCancel")); + Curl_GetAddrInfoExW = CURLX_FUNCTION_CAST(GETADDRINFOEXW_FN, + GetProcAddress(ws2_32Dll, "GetAddrInfoExW")); } #endif diff --git a/lib/system_win32.h b/lib/system_win32.h index 42bbb143f3..bd490cabcc 100644 --- a/lib/system_win32.h +++ b/lib/system_win32.h @@ -57,12 +57,16 @@ typedef struct addrinfoexW_ struct addrinfoexW_ *ai_next; } ADDRINFOEXW_; -typedef void(CALLBACK *LOOKUP_COMPLETION)(DWORD, DWORD, LPWSAOVERLAPPED); -extern void(WSAAPI *Curl_FreeAddrInfoExW)(ADDRINFOEXW_*); -extern int(WSAAPI *Curl_GetAddrInfoExCancel)(LPHANDLE); -extern int(WSAAPI *Curl_GetAddrInfoExW)(PCWSTR, PCWSTR, DWORD, LPGUID, +typedef void (CALLBACK *LOOKUP_COMPLETION_FN)(DWORD, DWORD, LPWSAOVERLAPPED); +typedef void (WSAAPI *FREEADDRINFOEXW_FN)(ADDRINFOEXW_*); +typedef int (WSAAPI *GETADDRINFOEXCANCEL_FN)(LPHANDLE); +typedef int (WSAAPI *GETADDRINFOEXW_FN)(PCWSTR, PCWSTR, DWORD, LPGUID, const ADDRINFOEXW_*, ADDRINFOEXW_**, struct timeval*, LPOVERLAPPED, - LOOKUP_COMPLETION, LPHANDLE); + LOOKUP_COMPLETION_FN, LPHANDLE); + +extern FREEADDRINFOEXW_FN Curl_FreeAddrInfoExW; +extern GETADDRINFOEXCANCEL_FN Curl_GetAddrInfoExCancel; +extern GETADDRINFOEXW_FN Curl_GetAddrInfoExW; /* This is used to dynamically load DLLs */ HMODULE Curl_load_library(LPCTSTR filename);