]> git.ipfire.org Git - thirdparty/pciutils.git/commitdiff
windows: Do not cast FARPROC to LPVOID and then to some function pointer
authorPali Rohár <pali@kernel.org>
Thu, 21 Nov 2024 22:51:26 +0000 (23:51 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 8 Jun 2025 15:19:58 +0000 (17:19 +0200)
FARPROC is function pointer type intptr_t(__stdcall*)() and LPVOID is data
pointer type void*. Casting from function pointer to data pointer and back
is undefined in C, and moreover in all cases it is not needed. In all cases
it is just needed to cast FARPROC function pointer type to some specific
function pointer type, and casting via intermediate LPVOID was there just
to mute compiler warnings about casting between two incompatible function
pointer types. To mute that compiler warning, do casting via intermediate
generic function pointer type void(*)(void) which is preferred according to
gcc documentation and does not throw any compiler warnings neither by gcc,
nor by msvc compilers.

lib/win32-helpers.c

index 0190f21531f29b4ce5dfbb9f475c9ac63906b9cb..3d514a2c95eec92fde2fa45fbf71eab726883f8f 100644 (file)
@@ -177,7 +177,7 @@ win32_change_error_mode(UINT new_mode)
    */
   kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
   if (kernel32)
-    MySetThreadErrorMode = (SetThreadErrorModeProt)(LPVOID)GetProcAddress(kernel32, "SetThreadErrorMode");
+    MySetThreadErrorMode = (SetThreadErrorModeProt)(void(*)(void))GetProcAddress(kernel32, "SetThreadErrorMode");
 
   if (MySetThreadErrorMode &&
       MySetThreadErrorMode(new_mode, &old_mode))
@@ -597,7 +597,7 @@ prepare_security_descriptor_for_set_operation(PSECURITY_DESCRIPTOR security_desc
   if (!advapi32)
     return FALSE;
 
-  MySetSecurityDescriptorControl = (SetSecurityDescriptorControlProt)(LPVOID)GetProcAddress(advapi32, "SetSecurityDescriptorControl");
+  MySetSecurityDescriptorControl = (SetSecurityDescriptorControlProt)(void(*)(void))GetProcAddress(advapi32, "SetSecurityDescriptorControl");
   if (!MySetSecurityDescriptorControl)
     return FALSE;
 
@@ -940,8 +940,8 @@ win32_find_and_open_process_for_query(LPCSTR exe_file)
    * kernel32.dll library with K32 prefix.
    */
   MyGetModuleFileNameExW = NULL;
-  MyGetProcessImageFileNameW = (GetProcessImageFileNameWProt)(LPVOID)GetProcAddress(kernel32, "K32GetProcessImageFileNameW");
-  MyEnumProcesses = (EnumProcessesProt)(LPVOID)GetProcAddress(kernel32, "K32EnumProcesses");
+  MyGetProcessImageFileNameW = (GetProcessImageFileNameWProt)(void(*)(void))GetProcAddress(kernel32, "K32GetProcessImageFileNameW");
+  MyEnumProcesses = (EnumProcessesProt)(void(*)(void))GetProcAddress(kernel32, "K32EnumProcesses");
   if (!MyGetProcessImageFileNameW || !MyEnumProcesses)
     {
       /*
@@ -960,9 +960,9 @@ win32_find_and_open_process_for_query(LPCSTR exe_file)
        * Windows XP and higher systems. On older versions is
        * available function GetModuleFileNameExW().
        */
-      MyGetProcessImageFileNameW = (GetProcessImageFileNameWProt)(LPVOID)GetProcAddress(psapi, "GetProcessImageFileNameW");
-      MyGetModuleFileNameExW = (GetModuleFileNameExWProt)(LPVOID)GetProcAddress(psapi, "GetModuleFileNameExW");
-      MyEnumProcesses = (EnumProcessesProt)(LPVOID)GetProcAddress(psapi, "EnumProcesses");
+      MyGetProcessImageFileNameW = (GetProcessImageFileNameWProt)(void(*)(void))GetProcAddress(psapi, "GetProcessImageFileNameW");
+      MyGetModuleFileNameExW = (GetModuleFileNameExWProt)(void(*)(void))GetProcAddress(psapi, "GetModuleFileNameExW");
+      MyEnumProcesses = (EnumProcessesProt)(void(*)(void))GetProcAddress(psapi, "EnumProcesses");
       if ((!MyGetProcessImageFileNameW && !MyGetModuleFileNameExW) || !MyEnumProcesses)
         {
           FreeLibrary(psapi);