From 78b0139bc3b2abb3038fff1fbdd66c3babdbd1e8 Mon Sep 17 00:00:00 2001 From: safocl Date: Sun, 4 Jan 2026 15:33:16 +0400 Subject: [PATCH] powerrename: fix union usage (#42845) ## Summary of the Pull Request ## PR Checklist - [x] Closes: #42843 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass ## Detailed Description of the Pull Request / Additional comments fix undefined behavior when using union in the `IFACEMETHODIMP CPowerRenameRegEx::PutFileTime(_In_ SYSTEMTIME fileTime)` function https://github.com/microsoft/PowerToys/blob/a69f7fa806539e0de6e9e901b4f651c512fdd54f/src/modules/powerrename/lib/PowerRenameRegEx.cpp#L299 ## Validation Steps Performed --- src/modules/powerrename/lib/PowerRenameRegEx.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/modules/powerrename/lib/PowerRenameRegEx.cpp b/src/modules/powerrename/lib/PowerRenameRegEx.cpp index aabf838a7a..e9ce4fa62a 100644 --- a/src/modules/powerrename/lib/PowerRenameRegEx.cpp +++ b/src/modules/powerrename/lib/PowerRenameRegEx.cpp @@ -344,19 +344,13 @@ IFACEMETHODIMP CPowerRenameRegEx::PutFlags(_In_ DWORD flags) IFACEMETHODIMP CPowerRenameRegEx::PutFileTime(_In_ SYSTEMTIME fileTime) { - union timeunion - { - FILETIME fileTime; - ULARGE_INTEGER ul; - }; + FILETIME ft1; + FILETIME ft2; - timeunion ft1; - timeunion ft2; + SystemTimeToFileTime(&m_fileTime, &ft1); + SystemTimeToFileTime(&fileTime, &ft2); - SystemTimeToFileTime(&m_fileTime, &ft1.fileTime); - SystemTimeToFileTime(&fileTime, &ft2.fileTime); - - if (ft2.ul.QuadPart != ft1.ul.QuadPart) + if (ft2.dwLowDateTime != ft1.dwLowDateTime || ft2.dwHighDateTime != ft1.dwHighDateTime) { m_fileTime = fileTime; m_useFileTime = true;