diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-07-30 09:26:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-30 09:26:36 +0200 |
commit | 71dbe398df6a70a2bdafb328b997f9264961b824 (patch) | |
tree | 929ed7f928c9cd90c58a1ff8e711b2305bafea56 | |
parent | 9da24f7e3d9d8c63e72f7bf985f9cefa52f80a68 (diff) | |
parent | 3502a85ba859fe1cad983d78e7b33f8e3d886e8d (diff) | |
download | redot-engine-71dbe398df6a70a2bdafb328b997f9264961b824.tar.gz |
Merge pull request #30943 from ibrahn/fix-win-gettime-aliasing
Fix strict-aliasing warning in OS_Windows::get_unix_time.
-rw-r--r-- | platform/windows/os_windows.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 4c7e35ed88..93d4482279 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -2252,9 +2252,17 @@ uint64_t OS_Windows::get_unix_time() const { FILETIME fep; SystemTimeToFileTime(&ep, &fep); - // FIXME: dereferencing type-punned pointer will break strict-aliasing rules (GCC warning) + // Type punning through unions (rather than pointer cast) as per: // https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime#remarks - return (*(uint64_t *)&ft - *(uint64_t *)&fep) / 10000000; + ULARGE_INTEGER ft_punning; + ft_punning.LowPart = ft.dwLowDateTime; + ft_punning.HighPart = ft.dwHighDateTime; + + ULARGE_INTEGER fep_punning; + fep_punning.LowPart = fep.dwLowDateTime; + fep_punning.HighPart = fep.dwHighDateTime; + + return (ft_punning.QuadPart - fep_punning.QuadPart) / 10000000; }; uint64_t OS_Windows::get_system_time_secs() const { |