]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
system_win32: fix a function pointer assignment warning
authorJay Satiro <raysatiro@yahoo.com>
Thu, 28 Dec 2023 00:01:46 +0000 (19:01 -0500)
committerJay Satiro <raysatiro@yahoo.com>
Thu, 28 Dec 2023 08:38:44 +0000 (03:38 -0500)
- 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

lib/system_win32.c
lib/system_win32.h

index dd34140d7265ce9e5f219cdcb64282be5941447a..d2862de9231031735eb509168085e47876432677 100644 (file)
@@ -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
 
index 42bbb143f311ff2ee369fe6c4686ff58abb7fbdb..bd490cabcc81cc384e43cea082dd04512fa50df4 100644 (file)
@@ -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);