aboutsummaryrefslogtreecommitdiffhomepage
path: root/win32
diff options
context:
space:
mode:
authormitchell <unknown>2020-01-03 19:38:10 -0500
committermitchell <unknown>2020-01-03 19:38:10 -0500
commit44613f75e63cf67cee55ac5fe8dad8ad35151165 (patch)
tree99a720f0345207e5890500370fa91dc88ce579aa /win32
parentd04419780a4096dd7d6ddc7c3959356fdc6e64a5 (diff)
downloadscintilla-mirror-44613f75e63cf67cee55ac5fe8dad8ad35151165.tar.gz
Backport: Use safe mechanism for converting between function pointers and void*.
Backport of changeset 7863:507307a6c315.
Diffstat (limited to 'win32')
-rw-r--r--win32/PlatWin.cxx13
1 files changed, 6 insertions, 7 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 6553b7486..296f7f0cc 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -2851,13 +2851,12 @@ public:
// Use GetProcAddress to get a pointer to the relevant function.
Function FindFunction(const char *name) noexcept override {
if (h) {
- // C++ standard doesn't like casts between function pointers and void pointers so use a union
- union {
- FARPROC fp;
- Function f;
- } fnConv;
- fnConv.fp = ::GetProcAddress(h, name);
- return fnConv.f;
+ // Use memcpy as it doesn't invoke undefined or conditionally defined behaviour.
+ FARPROC fp = ::GetProcAddress(h, name);
+ Function f = nullptr;
+ static_assert(sizeof(f) == sizeof(fp), "size mismatch");
+ memcpy(&f, &fp, sizeof(f));
+ return f;
} else {
return nullptr;
}