diff --git a/channels/audin/client/audin_main.c b/channels/audin/client/audin_main.c index 8f9002641..01ea72182 100644 --- a/channels/audin/client/audin_main.c +++ b/channels/audin/client/audin_main.c @@ -811,14 +811,10 @@ static UINT audin_load_device_plugin(AUDIN_PLUGIN* audin, const char* name, cons FREERDP_AUDIN_DEVICE_ENTRY_POINTS entryPoints = { 0 }; UINT error = ERROR_INTERNAL_ERROR; - union - { - PVIRTUALCHANNELENTRY pvce; - PFREERDP_AUDIN_DEVICE_ENTRY entry; - } cnv; - cnv.pvce = freerdp_load_channel_addin_entry(AUDIN_CHANNEL_NAME, name, NULL, 0); + PVIRTUALCHANNELENTRY pvce = freerdp_load_channel_addin_entry(AUDIN_CHANNEL_NAME, name, NULL, 0); + PFREERDP_AUDIN_DEVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PFREERDP_AUDIN_DEVICE_ENTRY); - if (cnv.entry == NULL) + if (entry == NULL) { WLog_Print(audin->log, WLOG_ERROR, "freerdp_load_channel_addin_entry did not return any function pointers for %s ", @@ -831,7 +827,7 @@ static UINT audin_load_device_plugin(AUDIN_PLUGIN* audin, const char* name, cons entryPoints.args = args; entryPoints.rdpcontext = audin->rdpcontext; - error = cnv.entry(&entryPoints); + error = entry(&entryPoints); if (error) { WLog_Print(audin->log, WLOG_ERROR, "%s entry returned error %" PRIu32 ".", name, error); diff --git a/channels/client/addin.c b/channels/client/addin.c index bdd9400b5..76d96b215 100644 --- a/channels/client/addin.c +++ b/channels/client/addin.c @@ -52,16 +52,9 @@ static void* freerdp_channels_find_static_entry_in_table(const STATIC_ENTRY_TABL while (pEntry->entry != NULL) { + static_entry_fn_t fkt = pEntry->entry; if (strcmp(pEntry->name, identifier) == 0) - { - union - { - void* pv; - static_entry_fn_t entry; - } cnv; - cnv.entry = pEntry->entry; - return cnv.pv; - } + return WINPR_FUNC_PTR_CAST(fkt, void*); pEntry = &table->table.cse[index++]; } @@ -494,20 +487,15 @@ PVIRTUALCHANNELENTRY freerdp_channels_load_static_addin_entry(LPCSTR pszName, LP 0) || /* we only want to know if strnlen is > 0 */ (strncmp(subsystems->name, pszSubsystem, MAX_PATH) == 0)) { - /* cast with union trick to avoid -Wcast-function-type-strict */ - union - { - PVIRTUALCHANNELENTRY pvce; - static_subsystem_entry_fn_t entry; - } cnv; - cnv.entry = subsystems->entry; + static_subsystem_entry_fn_t fkt = subsystems->entry; + if (pszType) { if (strncmp(subsystems->type, pszType, MAX_PATH) == 0) - return cnv.pvce; + return WINPR_FUNC_PTR_CAST(fkt, PVIRTUALCHANNELENTRY); } else - return cnv.pvce; + return WINPR_FUNC_PTR_CAST(fkt, PVIRTUALCHANNELENTRY); } } } diff --git a/channels/drdynvc/client/drdynvc_main.c b/channels/drdynvc/client/drdynvc_main.c index 16b15836d..0ca38887e 100644 --- a/channels/drdynvc/client/drdynvc_main.c +++ b/channels/drdynvc/client/drdynvc_main.c @@ -359,15 +359,11 @@ static UINT dvcman_load_addin(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager* WLog_Print(drdynvc->log, WLOG_INFO, "Loading Dynamic Virtual Channel %s", args->argv[0]); - union - { - PVIRTUALCHANNELENTRY pvce; - PDVC_PLUGIN_ENTRY pDVCPluginEntry; - } cnv; - cnv.pvce = + PVIRTUALCHANNELENTRY pvce = freerdp_load_channel_addin_entry(args->argv[0], NULL, NULL, FREERDP_ADDIN_CHANNEL_DYNAMIC); + PDVC_PLUGIN_ENTRY pDVCPluginEntry = WINPR_FUNC_PTR_CAST(pvce, PDVC_PLUGIN_ENTRY); - if (cnv.pDVCPluginEntry) + if (pDVCPluginEntry) { DVCMAN_ENTRY_POINTS entryPoints = { 0 }; @@ -379,7 +375,7 @@ static UINT dvcman_load_addin(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager* entryPoints.dvcman = (DVCMAN*)pChannelMgr; entryPoints.args = args; entryPoints.context = context; - return cnv.pDVCPluginEntry(&entryPoints.iface); + return pDVCPluginEntry(&entryPoints.iface); } return ERROR_INVALID_FUNCTION; diff --git a/channels/printer/client/printer_main.c b/channels/printer/client/printer_main.c index 8408a8a4c..f53a085b4 100644 --- a/channels/printer/client/printer_main.c +++ b/channels/printer/client/printer_main.c @@ -1049,18 +1049,13 @@ error_out: static rdpPrinterDriver* printer_load_backend(const char* backend) { typedef UINT (*backend_load_t)(rdpPrinterDriver**); - union - { - PVIRTUALCHANNELENTRY entry; - backend_load_t backend; - } fktconv; - - fktconv.entry = freerdp_load_channel_addin_entry("printer", backend, NULL, 0); - if (!fktconv.entry) + PVIRTUALCHANNELENTRY entry = freerdp_load_channel_addin_entry("printer", backend, NULL, 0); + backend_load_t func = WINPR_FUNC_PTR_CAST(entry, backend_load_t); + if (!func) return NULL; rdpPrinterDriver* printer = NULL; - const UINT rc = fktconv.backend(&printer); + const UINT rc = func(&printer); if (rc != CHANNEL_RC_OK) return NULL; diff --git a/channels/rdpdr/client/devman.c b/channels/rdpdr/client/devman.c index ddff156ae..5da3a410a 100644 --- a/channels/rdpdr/client/devman.c +++ b/channels/rdpdr/client/devman.c @@ -187,11 +187,6 @@ UINT devman_load_device_service(DEVMAN* devman, const RDPDR_DEVICE* device, rdpC const char* ServiceName = NULL; DEVICE_SERVICE_ENTRY_POINTS ep = { 0 }; union - { - PVIRTUALCHANNELENTRY pvce; - PDEVICE_SERVICE_ENTRY entry; - } cnv; - union { const RDPDR_DEVICE* cdp; RDPDR_DEVICE* dp; @@ -223,9 +218,11 @@ UINT devman_load_device_service(DEVMAN* devman, const RDPDR_DEVICE* device, rdpC else WLog_INFO(TAG, "Loading device service %s (static)", ServiceName); - cnv.pvce = freerdp_load_channel_addin_entry(ServiceName, NULL, "DeviceServiceEntry", 0); + PVIRTUALCHANNELENTRY pvce = + freerdp_load_channel_addin_entry(ServiceName, NULL, "DeviceServiceEntry", 0); + PDEVICE_SERVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PDEVICE_SERVICE_ENTRY); - if (!cnv.entry) + if (!entry) { WLog_INFO(TAG, "freerdp_load_channel_addin_entry failed!"); return ERROR_INTERNAL_ERROR; @@ -235,5 +232,5 @@ UINT devman_load_device_service(DEVMAN* devman, const RDPDR_DEVICE* device, rdpC ep.RegisterDevice = devman_register_device; ep.device = devconv.dp; ep.rdpcontext = rdpcontext; - return cnv.entry(&ep); + return entry(&ep); } diff --git a/channels/rdpsnd/client/rdpsnd_main.c b/channels/rdpsnd/client/rdpsnd_main.c index b9f275aec..f87ab007c 100644 --- a/channels/rdpsnd/client/rdpsnd_main.c +++ b/channels/rdpsnd/client/rdpsnd_main.c @@ -848,27 +848,23 @@ static void rdpsnd_register_device_plugin(rdpsndPlugin* rdpsnd, rdpsndDevicePlug static UINT rdpsnd_load_device_plugin(rdpsndPlugin* rdpsnd, const char* name, const ADDIN_ARGV* args) { - union - { - PVIRTUALCHANNELENTRY pvce; - PFREERDP_RDPSND_DEVICE_ENTRY entry; - } cnv; - FREERDP_RDPSND_DEVICE_ENTRY_POINTS entryPoints = { 0 }; UINT error = 0; DWORD flags = FREERDP_ADDIN_CHANNEL_STATIC | FREERDP_ADDIN_CHANNEL_ENTRYEX; if (rdpsnd->dynamic) flags = FREERDP_ADDIN_CHANNEL_DYNAMIC; - cnv.pvce = freerdp_load_channel_addin_entry(RDPSND_CHANNEL_NAME, name, NULL, flags); + PVIRTUALCHANNELENTRY pvce = + freerdp_load_channel_addin_entry(RDPSND_CHANNEL_NAME, name, NULL, flags); + PFREERDP_RDPSND_DEVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PFREERDP_RDPSND_DEVICE_ENTRY); - if (!cnv.entry) + if (!entry) return ERROR_INTERNAL_ERROR; entryPoints.rdpsnd = rdpsnd; entryPoints.pRegisterRdpsndDevice = rdpsnd_register_device_plugin; entryPoints.args = args; - error = cnv.entry(&entryPoints); + error = entry(&entryPoints); if (error) WLog_ERR(TAG, "%s %s entry returns error %" PRIu32 "", rdpsnd_is_dyn_str(rdpsnd->dynamic), name, error); diff --git a/channels/urbdrc/client/urbdrc_main.c b/channels/urbdrc/client/urbdrc_main.c index bf2044eaf..7f3d54354 100644 --- a/channels/urbdrc/client/urbdrc_main.c +++ b/channels/urbdrc/client/urbdrc_main.c @@ -770,21 +770,19 @@ static UINT urbdrc_load_udevman_addin(IWTSPlugin* pPlugin, LPCSTR name, const AD { URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)pPlugin; FREERDP_URBDRC_SERVICE_ENTRY_POINTS entryPoints = { 0 }; - union - { - PVIRTUALCHANNELENTRY pvce; - PFREERDP_URBDRC_DEVICE_ENTRY entry; - } cnv; - cnv.pvce = freerdp_load_channel_addin_entry(URBDRC_CHANNEL_NAME, name, NULL, 0); - if (!cnv.entry) + PVIRTUALCHANNELENTRY pvce = + freerdp_load_channel_addin_entry(URBDRC_CHANNEL_NAME, name, NULL, 0); + PFREERDP_URBDRC_DEVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PFREERDP_URBDRC_DEVICE_ENTRY); + + if (!entry) return ERROR_INVALID_OPERATION; entryPoints.plugin = pPlugin; entryPoints.pRegisterUDEVMAN = urbdrc_register_udevman_addin; entryPoints.args = args; - const UINT error = cnv.entry(&entryPoints); + const UINT error = entry(&entryPoints); if (error) { WLog_Print(urbdrc->log, WLOG_ERROR, "%s entry returns error.", name); diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 057da6df3..7d2b91752 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -5716,22 +5716,17 @@ fail: static BOOL freerdp_client_load_static_channel_addin(rdpChannels* channels, rdpSettings* settings, const char* name, void* data) { - union - { - PVIRTUALCHANNELENTRY pvce; - PVIRTUALCHANNELENTRYEX pvceex; - } cnv; PVIRTUALCHANNELENTRY entry = NULL; - - cnv.pvce = freerdp_load_channel_addin_entry( + PVIRTUALCHANNELENTRY pvce = freerdp_load_channel_addin_entry( name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC | FREERDP_ADDIN_CHANNEL_ENTRYEX); + PVIRTUALCHANNELENTRYEX pvceex = WINPR_FUNC_PTR_CAST(pvce, PVIRTUALCHANNELENTRYEX); - if (!cnv.pvceex) + if (!pvceex) entry = freerdp_load_channel_addin_entry(name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC); - if (cnv.pvceex) + if (pvceex) { - if (freerdp_channels_client_load_ex(channels, settings, cnv.pvceex, data) == 0) + if (freerdp_channels_client_load_ex(channels, settings, pvceex, data) == 0) { WLog_DBG(TAG, "loading channelEx %s", name); return TRUE; diff --git a/libfreerdp/common/addin.c b/libfreerdp/common/addin.c index c1755c5d2..d07e20880 100644 --- a/libfreerdp/common/addin.c +++ b/libfreerdp/common/addin.c @@ -237,13 +237,8 @@ PVIRTUALCHANNELENTRY freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPa if (!library) goto fail; - union - { - FARPROC fp; - PVIRTUALCHANNELENTRY entry; - } cnv; - cnv.fp = GetProcAddress(library, pszEntryName); - entry = cnv.entry; + FARPROC fp = GetProcAddress(library, pszEntryName); + entry = WINPR_FUNC_PTR_CAST(fp, PVIRTUALCHANNELENTRY); fail: free(pszRelativeFilePath); free(pszAddinFile); diff --git a/libfreerdp/core/childsession.c b/libfreerdp/core/childsession.c index 6643c2f1b..c03370175 100644 --- a/libfreerdp/core/childsession.c +++ b/libfreerdp/core/childsession.c @@ -470,19 +470,16 @@ static BOOL createChildSessionTransport(HANDLE* pFile) WCHAR pipePath[0x80] = { 0 }; char pipePathA[0x80] = { 0 }; - union - { - FARPROC fp; - WinStationCreateChildSessionTransportFn createChildSessionFn; - } cnv; - cnv.fp = GetProcAddress(hModule, "WinStationCreateChildSessionTransport"); - if (!cnv.createChildSessionFn) + FARPROC fp = GetProcAddress(hModule, "WinStationCreateChildSessionTransport"); + WinStationCreateChildSessionTransportFn createChildSessionFn = + WINPR_FUNC_PTR_CAST(fp, WinStationCreateChildSessionTransportFn); + if (!createChildSessionFn) { WLog_ERR(TAG, "unable to retrieve WinStationCreateChildSessionTransport function"); goto out; } - HRESULT hStatus = cnv.createChildSessionFn(pipePath, 0x80); + HRESULT hStatus = createChildSessionFn(pipePath, 0x80); if (!SUCCEEDED(hStatus)) { WLog_ERR(TAG, "error 0x%x when creating childSessionTransport", hStatus); diff --git a/libfreerdp/core/credssp_auth.c b/libfreerdp/core/credssp_auth.c index 43e16aae6..de979fe09 100644 --- a/libfreerdp/core/credssp_auth.c +++ b/libfreerdp/core/credssp_auth.c @@ -814,20 +814,17 @@ static SecurityFunctionTable* auth_resolve_sspi_table(const rdpSettings* setting WLog_INFO(TAG, "Using SSPI Module: %s", module_name); - union - { - FARPROC fp; - INIT_SECURITY_INTERFACE InitSecurityInterface_ptr; - } cnv; - cnv.fp = GetProcAddress(hSSPI, proc_name); - if (!cnv.InitSecurityInterface_ptr) + FARPROC fp = GetProcAddress(hSSPI, proc_name); + INIT_SECURITY_INTERFACE InitSecurityInterface_ptr = + WINPR_FUNC_PTR_CAST(fp, INIT_SECURITY_INTERFACE); + if (!InitSecurityInterface_ptr) { WLog_ERR(TAG, "Failed to load SSPI module: %s, no function %s", module_name, proc_name); free(sspi_module); return FALSE; } free(sspi_module); - return cnv.InitSecurityInterface_ptr(); + return InitSecurityInterface_ptr(); } return InitSecurityInterfaceEx(0); diff --git a/libfreerdp/crypto/tls.c b/libfreerdp/crypto/tls.c index 386ec7a84..3559038d7 100644 --- a/libfreerdp/crypto/tls.c +++ b/libfreerdp/crypto/tls.c @@ -539,17 +539,13 @@ static long bio_rdp_tls_callback_ctrl(BIO* bio, int cmd, bio_info_cb* fp) case BIO_CTRL_SET_CALLBACK: { typedef void (*fkt_t)(const SSL*, int, int); + /* Documented since https://www.openssl.org/docs/man1.1.1/man3/BIO_set_callback.html * the argument is not really of type bio_info_cb* and must be cast * to the required type */ - union - { - fkt_t fkt; - bio_info_cb* fp; - } cnv; - cnv.fp = fp; - SSL_set_info_callback(tls->ssl, cnv.fkt); + fkt_t fkt = WINPR_FUNC_PTR_CAST(fp, fkt_t); + SSL_set_info_callback(tls->ssl, fkt); status = 1; } break; diff --git a/libfreerdp/primitives/prim_copy.c b/libfreerdp/primitives/prim_copy.c index 895dc2eae..4b9eba748 100644 --- a/libfreerdp/primitives/prim_copy.c +++ b/libfreerdp/primitives/prim_copy.c @@ -377,16 +377,7 @@ void primitives_init_copy(primitives_t* prims) /* Start with the default. */ prims->copy_8u = general_copy_8u; prims->copy_8u_AC4r = general_copy_8u_AC4r; - /* This is just an alias with void* parameters - * cast with union trick to avoid -Wcast-function-type-strict - */ - union - { - __copy_8u_t ufkt; - __copy_t fkt; - } cnv; - cnv.ufkt = prims->copy_8u; - prims->copy = cnv.fkt; + prims->copy = WINPR_FUNC_PTR_CAST(prims->copy_8u, __copy_t); prims->copy_no_overlap = generic_image_copy_no_overlap; } diff --git a/server/proxy/pf_client.c b/server/proxy/pf_client.c index 8a03e8605..3e53b1b68 100644 --- a/server/proxy/pf_client.c +++ b/server/proxy/pf_client.c @@ -194,21 +194,15 @@ static BOOL freerdp_client_load_static_channel_addin(rdpChannels* channels, rdpS const char* name, void* data) { PVIRTUALCHANNELENTRY entry = NULL; - union - { - PVIRTUALCHANNELENTRY entry; - PVIRTUALCHANNELENTRYEX entryEx; - } cnv; - - cnv.entry = freerdp_load_channel_addin_entry( + PVIRTUALCHANNELENTRY lentry = freerdp_load_channel_addin_entry( name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC | FREERDP_ADDIN_CHANNEL_ENTRYEX); - - if (!cnv.entryEx) + PVIRTUALCHANNELENTRYEX entryEx = WINPR_FUNC_PTR_CAST(lentry, PVIRTUALCHANNELENTRYEX); + if (!entryEx) entry = freerdp_load_channel_addin_entry(name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC); - if (cnv.entryEx) + if (entryEx) { - if (freerdp_channels_client_load_ex(channels, settings, cnv.entryEx, data) == 0) + if (freerdp_channels_client_load_ex(channels, settings, entryEx, data) == 0) { WLog_INFO(TAG, "loading channelEx %s", name); return TRUE; diff --git a/server/proxy/pf_modules.c b/server/proxy/pf_modules.c index 406d8d8b9..2c5c32bf9 100644 --- a/server/proxy/pf_modules.c +++ b/server/proxy/pf_modules.c @@ -491,13 +491,9 @@ static BOOL pf_modules_load_module(const char* module_path, proxyModule* module, return FALSE; } - union - { - FARPROC fp; - proxyModuleEntryPoint pEntryPoint; - } cnv; - cnv.fp = GetProcAddress(handle, MODULE_ENTRY_POINT); - if (!cnv.pEntryPoint) + FARPROC fp = GetProcAddress(handle, MODULE_ENTRY_POINT); + proxyModuleEntryPoint pEntryPoint = WINPR_FUNC_PTR_CAST(fp, proxyModuleEntryPoint); + if (!pEntryPoint) { WLog_ERR(TAG, "GetProcAddress failed while loading %s", module_path); goto error; @@ -507,7 +503,7 @@ static BOOL pf_modules_load_module(const char* module_path, proxyModule* module, WLog_ERR(TAG, "ArrayList_Append failed!"); goto error; } - return pf_modules_add(module, cnv.pEntryPoint, userdata); + return pf_modules_add(module, pEntryPoint, userdata); error: FreeLibrary(handle); diff --git a/winpr/include/winpr/winpr.h b/winpr/include/winpr/winpr.h index a429c7a11..0f2558cc5 100644 --- a/winpr/include/winpr/winpr.h +++ b/winpr/include/winpr/winpr.h @@ -136,4 +136,19 @@ WINPR_API const char* winpr_get_build_config(void); #define WINPR_UNUSED(x) (void)(x) +#if defined(__GNUC__) || defined(__clang__) +#define WINPR_FUNC_PTR_CAST(ptr, dstType) \ + ({ \ + union \ + { \ + typeof(ptr) src; \ + dstType dst; \ + } cnv; \ + cnv.src = ptr; \ + cnv.dst; \ + }) +#else +#define WINPR_FUNC_PTR_CAST(ptr, dstType) (dstType)(uintptr_t) ptr +#endif + #endif /* WINPR_H */ diff --git a/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c b/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c index f8f54a657..7bfdfabdb 100644 --- a/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c +++ b/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c @@ -47,13 +47,13 @@ int TestLibraryGetProcAddress(int argc, char* argv[]) return -1; } - if (!(pFunctionA = (TEST_AB_FN)GetProcAddress(library, "FunctionA"))) + if (!(pFunctionA = WINPR_FUNC_PTR_CAST(GetProcAddress(library, "FunctionA"), TEST_AB_FN))) { printf("%s: GetProcAddress failure (FunctionA)\n", __func__); return -1; } - if (!(pFunctionB = (TEST_AB_FN)GetProcAddress(library, "FunctionB"))) + if (!(pFunctionB = WINPR_FUNC_PTR_CAST(GetProcAddress(library, "FunctionB"), TEST_AB_FN))) { printf("%s: GetProcAddress failure (FunctionB)\n", __func__); return -1; diff --git a/winpr/libwinpr/ncrypt/ncrypt.c b/winpr/libwinpr/ncrypt/ncrypt.c index 7155f6397..87d8cb892 100644 --- a/winpr/libwinpr/ncrypt/ncrypt.c +++ b/winpr/libwinpr/ncrypt/ncrypt.c @@ -267,15 +267,15 @@ SECURITY_STATUS winpr_NCryptOpenStorageProviderEx(NCRYPT_PROV_HANDLE* phProvider { typedef SECURITY_STATUS (*NCryptOpenStorageProviderFn)(NCRYPT_PROV_HANDLE * phProvider, LPCWSTR pszProviderName, DWORD dwFlags); - NCryptOpenStorageProviderFn ncryptOpenStorageProviderFn; - SECURITY_STATUS ret; + SECURITY_STATUS ret = NTE_PROV_DLL_NOT_FOUND; HANDLE lib = LoadLibraryA("ncrypt.dll"); if (!lib) return NTE_PROV_DLL_NOT_FOUND; - ncryptOpenStorageProviderFn = - (NCryptOpenStorageProviderFn)GetProcAddress(lib, "NCryptOpenStorageProvider"); - if (!ncryptOpenStorageProviderFn) + FARPROC fp = GetProcAddress(lib, "NCryptOpenStorageProvider"); + NCryptOpenStorageProviderFn ncryptOpenStorageProviderFn = + WINPR_FUNC_PTR_CAST(fp, NCryptOpenStorageProviderFn); + (NCryptOpenStorageProviderFn) if (!ncryptOpenStorageProviderFn) { ret = NTE_PROV_DLL_NOT_FOUND; goto out_free_lib; diff --git a/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c b/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c index 2a6b99bf3..4a7d48741 100644 --- a/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c +++ b/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c @@ -1261,20 +1261,16 @@ SECURITY_STATUS NCryptOpenP11StorageProviderEx(NCRYPT_PROV_HANDLE* phProvider, goto out_load_library; } - union - { - FARPROC fp; - c_get_function_list_t c_get_function_list; - } cnv; - cnv.fp = GetProcAddress(library, "C_GetFunctionList"); + FARPROC fp = GetProcAddress(library, "C_GetFunctionList"); + c_get_function_list_t c_get_function_list = WINPR_FUNC_PTR_CAST(fp, c_get_function_list_t); - if (!cnv.c_get_function_list) + if (!c_get_function_list) { status = NTE_PROV_TYPE_ENTRY_BAD; goto out_load_library; } - status = initialize_pkcs11(library, cnv.c_get_function_list, phProvider); + status = initialize_pkcs11(library, c_get_function_list, phProvider); if (status != ERROR_SUCCESS) { status = NTE_PROVIDER_DLL_FAIL; diff --git a/winpr/libwinpr/pool/callback.c b/winpr/libwinpr/pool/callback.c index 1a4dde15d..d4ac8a641 100644 --- a/winpr/libwinpr/pool/callback.c +++ b/winpr/libwinpr/pool/callback.c @@ -26,15 +26,17 @@ #ifdef WINPR_THREAD_POOL #ifdef _WIN32 +typedef BOOL(WINAPI* pCallbackMayRunLong_t)(PTP_CALLBACK_INSTANCE pci); static INIT_ONCE init_once_module = INIT_ONCE_STATIC_INIT; -static BOOL(WINAPI* pCallbackMayRunLong)(PTP_CALLBACK_INSTANCE pci); +static pCallbackMayRunLong_t pCallbackMayRunLong = NULL; static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context) { HMODULE kernel32 = LoadLibraryA("kernel32.dll"); if (kernel32) { - pCallbackMayRunLong = (void*)GetProcAddress(kernel32, "CallbackMayRunLong"); + FARPROC fp = GetProcAddress(kernel32, "CallbackMayRunLong"); + pCallbackMayRunLong = WINPR_FUNC_PTR_CAST(fp, pCallbackMayRunLong_t); } return TRUE; } diff --git a/winpr/libwinpr/smartcard/smartcard.c b/winpr/libwinpr/smartcard/smartcard.c index 0a7966388..4979c537b 100644 --- a/winpr/libwinpr/smartcard/smartcard.c +++ b/winpr/libwinpr/smartcard/smartcard.c @@ -1100,13 +1100,14 @@ WINSCARDAPI char* WINAPI SCardGetReaderStateString(DWORD dwReaderState) return buffer; } -#define WINSCARD_LOAD_PROC(_name, ...) \ - do \ - { \ - WINPR_PRAGMA_DIAG_PUSH \ - WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \ - pWinSCardApiTable->pfn##_name = (fn##_name)GetProcAddress(hWinSCardLibrary, #_name); \ - WINPR_PRAGMA_DIAG_POP \ +#define WINSCARD_LOAD_PROC(_name, ...) \ + do \ + { \ + WINPR_PRAGMA_DIAG_PUSH \ + WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \ + FARPROC fp = GetProcAddress(hWinSCardLibrary, #_name); \ + pWinSCardApiTable->pfn##_name = WINPR_FUNC_PTR_CAST(fp, fn##_name); \ + WINPR_PRAGMA_DIAG_POP \ } while (0) BOOL WinSCard_LoadApiTableFunctions(PSCardApiFunctionTable pWinSCardApiTable, diff --git a/winpr/libwinpr/smartcard/smartcard_pcsc.c b/winpr/libwinpr/smartcard/smartcard_pcsc.c index 29aed1bf7..297b014c5 100644 --- a/winpr/libwinpr/smartcard/smartcard_pcsc.c +++ b/winpr/libwinpr/smartcard/smartcard_pcsc.c @@ -48,13 +48,13 @@ #include "../log.h" #define TAG WINPR_TAG("smartcard") -#define WINSCARD_LOAD_PROC_EX(module, pcsc, _fname, _name, ...) \ - do \ - { \ - WINPR_PRAGMA_DIAG_PUSH \ - WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \ - pcsc.pfn##_fname = (fnPCSC##_fname)GetProcAddress(module, #_name); \ - WINPR_PRAGMA_DIAG_POP \ +#define WINSCARD_LOAD_PROC_EX(module, pcsc, _fname, _name, ...) \ + do \ + { \ + WINPR_PRAGMA_DIAG_PUSH \ + WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \ + pcsc.pfn##_fname = WINPR_FUNC_PTR_CAST(GetProcAddress(module, #_name), fnPCSC##_fname); \ + WINPR_PRAGMA_DIAG_POP \ } while (0) #define WINSCARD_LOAD_PROC(module, pcsc, _name, ...) \ diff --git a/winpr/libwinpr/sspi/sspi.c b/winpr/libwinpr/sspi/sspi.c index 4e10d6167..dbfa817e1 100644 --- a/winpr/libwinpr/sspi/sspi.c +++ b/winpr/libwinpr/sspi/sspi.c @@ -107,10 +107,10 @@ BOOL InitializeSspiModule_Native(void) if (!g_SspiModule) return FALSE; - pInitSecurityInterfaceW = - (INIT_SECURITY_INTERFACE_W)GetProcAddress(g_SspiModule, "InitSecurityInterfaceW"); - pInitSecurityInterfaceA = - (INIT_SECURITY_INTERFACE_A)GetProcAddress(g_SspiModule, "InitSecurityInterfaceA"); + pInitSecurityInterfaceW = WINPR_FUNC_PTR_CAST( + GetProcAddress(g_SspiModule, "InitSecurityInterfaceW"), INIT_SECURITY_INTERFACE_W); + pInitSecurityInterfaceA = WINPR_FUNC_PTR_CAST( + GetProcAddress(g_SspiModule, "InitSecurityInterfaceA"), INIT_SECURITY_INTERFACE_A); if (pInitSecurityInterfaceW) { @@ -124,11 +124,12 @@ BOOL InitializeSspiModule_Native(void) g_SspiW->dwVersion = SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_3; - g_SspiW->SetContextAttributesW = - (SET_CONTEXT_ATTRIBUTES_FN_W)GetProcAddress(g_SspiModule, "SetContextAttributesW"); + g_SspiW->SetContextAttributesW = WINPR_FUNC_PTR_CAST( + GetProcAddress(g_SspiModule, "SetContextAttributesW"), SET_CONTEXT_ATTRIBUTES_FN_W); - g_SspiW->SetCredentialsAttributesW = (SET_CREDENTIALS_ATTRIBUTES_FN_W)GetProcAddress( - g_SspiModule, "SetCredentialsAttributesW"); + g_SspiW->SetCredentialsAttributesW = + WINPR_FUNC_PTR_CAST(GetProcAddress(g_SspiModule, "SetCredentialsAttributesW"), + SET_CREDENTIALS_ATTRIBUTES_FN_W); } } @@ -144,11 +145,12 @@ BOOL InitializeSspiModule_Native(void) g_SspiA->dwVersion = SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_3; - g_SspiA->SetContextAttributesA = - (SET_CONTEXT_ATTRIBUTES_FN_W)GetProcAddress(g_SspiModule, "SetContextAttributesA"); + g_SspiA->SetContextAttributesA = WINPR_FUNC_PTR_CAST( + GetProcAddress(g_SspiModule, "SetContextAttributesA"), SET_CONTEXT_ATTRIBUTES_FN_W); - g_SspiA->SetCredentialsAttributesA = (SET_CREDENTIALS_ATTRIBUTES_FN_W)GetProcAddress( - g_SspiModule, "SetCredentialsAttributesA"); + g_SspiA->SetCredentialsAttributesA = + WINPR_FUNC_PTR_CAST(GetProcAddress(g_SspiModule, "SetCredentialsAttributesA"), + SET_CREDENTIALS_ATTRIBUTES_FN_W); } } diff --git a/winpr/libwinpr/synch/barrier.c b/winpr/libwinpr/synch/barrier.c index 002140859..ec77be908 100644 --- a/winpr/libwinpr/synch/barrier.c +++ b/winpr/libwinpr/synch/barrier.c @@ -70,12 +70,14 @@ static BOOL CALLBACK InitOnce_Barrier(PINIT_ONCE once, PVOID param, PVOID* conte pfnInitializeSynchronizationBarrier = (fnInitializeSynchronizationBarrier)GetProcAddress( g_Kernel32, "InitializeSynchronizationBarrier"); - pfnEnterSynchronizationBarrier = - (fnEnterSynchronizationBarrier)GetProcAddress(g_Kernel32, "EnterSynchronizationBarrier"); - - pfnDeleteSynchronizationBarrier = - (fnDeleteSynchronizationBarrier)GetProcAddress(g_Kernel32, "DeleteSynchronizationBarrier"); - + { + FARPROC fp = GetProcAddress(g_Kernel32, "EnterSynchronizationBarrier"); + pfnEnterSynchronizationBarrier = WINPR_FUNC_PTR_CAST(fp, fnEnterSynchronizationBarrier); + } + { + FARPROC fp = GetProcAddress(g_Kernel32, "DeleteSynchronizationBarrier"); + pfnDeleteSynchronizationBarrier = WINPR_FUNC_PTR_CAST(fp, fnDeleteSynchronizationBarrier); + } if (pfnInitializeSynchronizationBarrier && pfnEnterSynchronizationBarrier && pfnDeleteSynchronizationBarrier) { diff --git a/winpr/libwinpr/wtsapi/wtsapi.c b/winpr/libwinpr/wtsapi/wtsapi.c index ce6f24699..7b481d718 100644 --- a/winpr/libwinpr/wtsapi/wtsapi.c +++ b/winpr/libwinpr/wtsapi/wtsapi.c @@ -700,17 +700,13 @@ static BOOL LoadAndInitialize(char* library) if (!g_WtsApiModule) return FALSE; - union - { - FARPROC fp; - INIT_WTSAPI_FN pInitWtsApi; - } cnv; - cnv.fp = GetProcAddress(g_WtsApiModule, "InitWtsApi"); + FARPROC fp = GetProcAddress(g_WtsApiModule, "InitWtsApi"); + INIT_WTSAPI_FN pInitWtsApi = WINPR_FUNC_PTR_CAST(fp, INIT_WTSAPI_FN); - if (!cnv.pInitWtsApi) + if (!pInitWtsApi) return FALSE; - g_WtsApi = cnv.pInitWtsApi(); + g_WtsApi = pInitWtsApi(); return TRUE; }