File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed
Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -138,11 +138,13 @@ static int lookup_functions()
138138 goto err ;
139139 }
140140
141- #if defined(__GNUC__ )
142- # pragma GCC diagnostic push
143- # pragma GCC diagnostic ignored "-Wcast-function-type"
144- #endif
145- #define RESOLVE (lib_handle , x ) x = (x##_)GetProcAddress(lib_handle, #x); if (!x) goto err;
141+ /* Avoid direct function-pointer cast from FARPROC to typed callback pointer.
142+ Using memcpy keeps this warning-free regardless of the compiler and compiler settings. */
143+ #define RESOLVE (lib_handle , x ) do { \
144+ FARPROC proc_addr = GetProcAddress(lib_handle, #x); \
145+ if (!proc_addr) goto err; \
146+ memcpy(&x, &proc_addr, sizeof(x)); \
147+ } while (0)
146148
147149 RESOLVE (hid_lib_handle , HidD_GetHidGuid );
148150 RESOLVE (hid_lib_handle , HidD_GetAttributes );
@@ -167,9 +169,6 @@ static int lookup_functions()
167169 RESOLVE (cfgmgr32_lib_handle , CM_Get_Device_Interface_ListW );
168170
169171#undef RESOLVE
170- #if defined(__GNUC__ )
171- # pragma GCC diagnostic pop
172- #endif
173172
174173 return 0 ;
175174
You can’t perform that action at this time.
0 commit comments