diff options
| author | mitchell <unknown> | 2020-01-03 19:38:10 -0500 |
|---|---|---|
| committer | mitchell <unknown> | 2020-01-03 19:38:10 -0500 |
| commit | 44613f75e63cf67cee55ac5fe8dad8ad35151165 (patch) | |
| tree | 99a720f0345207e5890500370fa91dc88ce579aa /qt/ScintillaEditBase/PlatQt.cpp | |
| parent | d04419780a4096dd7d6ddc7c3959356fdc6e64a5 (diff) | |
| download | scintilla-mirror-44613f75e63cf67cee55ac5fe8dad8ad35151165.tar.gz | |
Backport: Use safe mechanism for converting between function pointers and void*.
Backport of changeset 7863:507307a6c315.
Diffstat (limited to 'qt/ScintillaEditBase/PlatQt.cpp')
| -rw-r--r-- | qt/ScintillaEditBase/PlatQt.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp index b4ea7a7d0..281fdba3d 100644 --- a/qt/ScintillaEditBase/PlatQt.cpp +++ b/qt/ScintillaEditBase/PlatQt.cpp @@ -1110,17 +1110,17 @@ public: } Function FindFunction(const char *name) override { if (lib) { - // C++ standard doesn't like casts between function pointers and void pointers so use a union - union { + // Use memcpy as it doesn't invoke undefined or conditionally defined behaviour. #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - QFunctionPointer fp; + QFunctionPointer fp {}; #else - void *fp; + void *fp = nullptr; #endif - Function f; - } fnConv; - fnConv.fp = lib->resolve(name); - return fnConv.f; + fp = lib->resolve(name); + Function f = nullptr; + static_assert(sizeof(f) == sizeof(fp), "size mismatch"); + memcpy(&f, &fp, sizeof(f)); + return f; } return nullptr; } |
