Skip to content

Commit 8cb5cc3

Browse files
authored
Fix MSVC extension warnings in WinAPITestHelper (#1492)
The implicit function-to-object pointer conversions triggered Clang's "-Wmicrosoft-cast" warning. Let's use the alias to a generic function-pointer type ("void (*)()") and "reinterpret_cast" at the two boundaries that produce specific function-pointer types. WinAPITestHelper is used only for unit tests, so there must be no risk in the production code. PiperOrigin-RevId: 906750097
1 parent b021114 commit 8cb5cc3

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/base/win32/win_api_test_helper.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ class HookTargetInfo {
114114
continue;
115115
}
116116
const FunctionPointer original_proc_address =
117-
::GetProcAddress(module_handle, request.proc_name.c_str());
117+
reinterpret_cast<FunctionPointer>(
118+
::GetProcAddress(module_handle, request.proc_name.c_str()));
118119
if (original_proc_address == nullptr) {
119120
LOG(FATAL) << "GetProcAddress returned nullptr.";
120121
continue;

src/base/win32/win_api_test_helper.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class WinAPITestHelper {
7474
class RestoreInfo;
7575
typedef RestoreInfo* RestoreInfoHandle;
7676

77-
typedef void* FunctionPointer;
77+
using FunctionPointer = void (*)();
7878
struct HookRequest {
7979
public:
8080
HookRequest(const std::string& src_module, const std::string& src_proc_name,
@@ -88,7 +88,8 @@ class WinAPITestHelper {
8888
static HookRequest MakeHookRequest(const std::string& module,
8989
const std::string& proc_name,
9090
const NewProcType& new_proc_ref) {
91-
return HookRequest(module, proc_name, &new_proc_ref);
91+
return HookRequest(module, proc_name,
92+
reinterpret_cast<FunctionPointer>(&new_proc_ref));
9293
}
9394

9495
// Overwrites on-memory Import Address Table (IAT) of |target_module| with

0 commit comments

Comments
 (0)