aboutsummaryrefslogtreecommitdiffhomepage
path: root/win32/PlatWin.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2019-12-13 14:55:15 +1100
committerNeil <nyamatongwe@gmail.com>2019-12-13 14:55:15 +1100
commiteab0c872c43486e670cb0157f83910982e3ad10b (patch)
tree1a58ba1c9c1bcfa7d7c74598ca6e443bd2f2959e /win32/PlatWin.cxx
parent952cd885fb6055c1e133ca53e3348d0e0b9d6cab (diff)
downloadscintilla-mirror-eab0c872c43486e670cb0157f83910982e3ad10b.tar.gz
Use safe mechanism for converting between function pointers and void*.
Diffstat (limited to 'win32/PlatWin.cxx')
-rw-r--r--win32/PlatWin.cxx13
1 files changed, 6 insertions, 7 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 73ac50271..4c9291fd1 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -3257,13 +3257,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));
+ memcpy(&f, &fp, sizeof(f));
+ return f;
} else {
return nullptr;
}