From a743e496c5d3ce98e38447a7b0f9b74065edd248 Mon Sep 17 00:00:00 2001 From: sosssego Date: Wed, 8 Feb 2023 11:00:19 +0000 Subject: [PATCH] [Analyzers][CPP]Changes to fix warning 26493 on src/common (#23467) * Changes to fix warning 26493 on src/common It will be multi PR change. This does not turn on the rule but fix the code under src/commom * int cast --- src/common/GPOWrapper/GPOWrapper.cpp | 54 +++++++++---------- src/common/SettingsAPI/settings_objects.cpp | 2 +- src/common/SettingsAPI/settings_objects.h | 2 +- src/common/Themes/icon_helpers.cpp | 6 +-- src/common/Themes/theme_helpers.cpp | 5 +- src/common/Themes/theme_listener.cpp | 2 +- src/common/Themes/windows_colors.cpp | 2 +- src/common/interop/keyboard_layout.cpp | 2 +- .../interop/two_way_pipe_message_ipc.cpp | 20 +++---- src/common/utils/HDropIterator.h | 8 +-- src/common/utils/HttpClient.h | 2 +- src/common/utils/UnhandledExceptionHandler.h | 4 +- src/common/utils/elevation.h | 4 +- src/common/utils/gpo.h | 6 +-- src/common/utils/process_path.h | 4 +- src/common/utils/registry.h | 2 +- src/common/utils/timeutil.h | 2 +- src/common/utils/winapi_error.h | 4 +- src/common/utils/window.h | 4 +- 19 files changed, 66 insertions(+), 69 deletions(-) diff --git a/src/common/GPOWrapper/GPOWrapper.cpp b/src/common/GPOWrapper/GPOWrapper.cpp index 513ba8a5c1c6..08948db0d1cc 100644 --- a/src/common/GPOWrapper/GPOWrapper.cpp +++ b/src/common/GPOWrapper/GPOWrapper.cpp @@ -6,110 +6,110 @@ namespace winrt::PowerToys::GPOWrapper::implementation { GpoRuleConfigured GPOWrapper::GetConfiguredAlwaysOnTopEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredAlwaysOnTopEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredAlwaysOnTopEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredAwakeEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredAwakeEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredAwakeEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredColorPickerEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredColorPickerEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredColorPickerEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredFancyZonesEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredFancyZonesEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredFancyZonesEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredFileLocksmithEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredFileLocksmithEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredFileLocksmithEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredSvgPreviewEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredSvgPreviewEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredSvgPreviewEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredMarkdownPreviewEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredMarkdownPreviewEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredMarkdownPreviewEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredMonacoPreviewEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredMonacoPreviewEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredMonacoPreviewEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredPdfPreviewEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredPdfPreviewEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredPdfPreviewEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredGcodePreviewEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredGcodePreviewEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredGcodePreviewEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredSvgThumbnailsEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredSvgThumbnailsEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredSvgThumbnailsEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredPdfThumbnailsEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredPdfThumbnailsEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredPdfThumbnailsEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredGcodeThumbnailsEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredGcodeThumbnailsEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredGcodeThumbnailsEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredStlThumbnailsEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredStlThumbnailsEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredStlThumbnailsEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredHostsFileEditorEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredHostsFileEditorEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredHostsFileEditorEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredImageResizerEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredImageResizerEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredImageResizerEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredKeyboardManagerEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredKeyboardManagerEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredKeyboardManagerEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredFindMyMouseEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredFindMyMouseEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredFindMyMouseEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredMouseHighlighterEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredMouseHighlighterEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredMouseHighlighterEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredMousePointerCrosshairsEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredMousePointerCrosshairsEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredMousePointerCrosshairsEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredPowerRenameEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredPowerRenameEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredPowerRenameEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredPowerLauncherEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredPowerLauncherEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredPowerLauncherEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredQuickAccentEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredQuickAccentEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredQuickAccentEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredScreenRulerEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredScreenRulerEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredScreenRulerEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredShortcutGuideEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredShortcutGuideEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredShortcutGuideEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredTextExtractorEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredTextExtractorEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredTextExtractorEnabledValue()); } GpoRuleConfigured GPOWrapper::GetConfiguredVideoConferenceMuteEnabledValue() { - return (GpoRuleConfigured)powertoys_gpo::getConfiguredVideoConferenceMuteEnabledValue(); + return static_cast(powertoys_gpo::getConfiguredVideoConferenceMuteEnabledValue()); } } diff --git a/src/common/SettingsAPI/settings_objects.cpp b/src/common/SettingsAPI/settings_objects.cpp index f7bd57384547..6f3aa4c792dc 100644 --- a/src/common/SettingsAPI/settings_objects.cpp +++ b/src/common/SettingsAPI/settings_objects.cpp @@ -247,7 +247,7 @@ namespace PowerToysSettings bool Settings::serialize_to_buffer(wchar_t* buffer, int* buffer_size) { auto result = m_json.Stringify(); - const int result_len = (int)result.size() + 1; + const int result_len = static_cast(result.size() + 1); if (buffer == nullptr || *buffer_size < result_len) { diff --git a/src/common/SettingsAPI/settings_objects.h b/src/common/SettingsAPI/settings_objects.h index cee95d7a56a4..1c84ac19b7d5 100644 --- a/src/common/SettingsAPI/settings_objects.h +++ b/src/common/SettingsAPI/settings_objects.h @@ -220,7 +220,7 @@ namespace PowerToysSettings std::array key_states{}; // Zero-initialize std::array output; const UINT wFlags = 1 << 2; // If bit 2 is set, keyboard state is not changed (Windows 10, version 1607 and newer) - auto output_bytes = ToUnicodeEx(key_code, scan_code, key_states.data(), output.data(), (int)output.size() - 1, wFlags, layout); + auto output_bytes = ToUnicodeEx(key_code, scan_code, key_states.data(), output.data(), static_cast(output.size()) - 1, wFlags, layout); if (output_bytes <= 0) { // If ToUnicodeEx fails (e.g. for F1-F12 keys) use GetKeyNameTextW diff --git a/src/common/Themes/icon_helpers.cpp b/src/common/Themes/icon_helpers.cpp index e5387e85a945..c426a0c747a9 100644 --- a/src/common/Themes/icon_helpers.cpp +++ b/src/common/Themes/icon_helpers.cpp @@ -14,7 +14,7 @@ HRESULT GetIconIndexFromPath(_In_ PCWSTR path, _Out_ int* index) if (!PathIsRelative(path)) { DWORD attrib = GetFileAttributes(path); - HIMAGELIST himl = (HIMAGELIST)SHGetFileInfo(path, attrib, &shFileInfo, sizeof(shFileInfo), (SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES)); + auto himl =SHGetFileInfo(path, attrib, &shFileInfo, sizeof(shFileInfo), (SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES)); if (himl) { *index = shFileInfo.iIcon; @@ -61,14 +61,14 @@ HBITMAP CreateBitmapFromIcon(_In_ HICON hIcon, _In_opt_ UINT width, _In_opt_ UIN if (hBitmap != NULL) { // Select bitmap into DC - HBITMAP hBitmapOld = (HBITMAP)SelectObject(hDC, hBitmap); + HBITMAP hBitmapOld = static_cast(SelectObject(hDC, hBitmap)); if (hBitmapOld != NULL) { // Draw icon into DC if (DrawIconEx(hDC, 0, 0, hIcon, rc.right, rc.bottom, 0, NULL, DI_NORMAL)) { // Restore original bitmap in DC - hBitmapResult = (HBITMAP)SelectObject(hDC, hBitmapOld); + hBitmapResult = static_cast(SelectObject(hDC, hBitmapOld)); hBitmapOld = NULL; hBitmap = NULL; } diff --git a/src/common/Themes/theme_helpers.cpp b/src/common/Themes/theme_helpers.cpp index 280eda9ded8f..c00bd92f76b6 100644 --- a/src/common/Themes/theme_helpers.cpp +++ b/src/common/Themes/theme_helpers.cpp @@ -28,10 +28,7 @@ AppTheme ThemeHelpers::GetAppTheme() } // convert bytes written to our buffer to an int, assuming little-endian - auto i = int(buffer[3] << 24 | - buffer[2] << 16 | - buffer[1] << 8 | - buffer[0]); + auto i = static_cast(buffer[3] << 24 | buffer[2] << 16 | buffer[1] << 8 | buffer[0]); return AppTheme(i); } diff --git a/src/common/Themes/theme_listener.cpp b/src/common/Themes/theme_listener.cpp index fb81a42e4c2d..3a31b0db3cf7 100644 --- a/src/common/Themes/theme_listener.cpp +++ b/src/common/Themes/theme_listener.cpp @@ -8,7 +8,7 @@ #pragma warning(disable : 4702) DWORD WINAPI _checkTheme(LPVOID lpParam) { - auto listener = (ThemeListener*)lpParam; + auto listener = static_cast(lpParam); listener->CheckTheme(); return 0; } diff --git a/src/common/Themes/windows_colors.cpp b/src/common/Themes/windows_colors.cpp index a30329c1814e..e5a8eec73201 100644 --- a/src/common/Themes/windows_colors.cpp +++ b/src/common/Themes/windows_colors.cpp @@ -11,7 +11,7 @@ DWORD WindowsColors::rgb_color(DWORD abgr_color) } DWORD WindowsColors::rgb_color(winrt::Windows::UI::Color color) { - return ((DWORD)color.R << 16) | ((DWORD)color.G << 8) | ((DWORD)color.B); + return static_cast((color.R << 16) | (color.G << 8) | (color.B)); } WindowsColors::Color WindowsColors::get_button_face_color() { diff --git a/src/common/interop/keyboard_layout.cpp b/src/common/interop/keyboard_layout.cpp index 441059bbb050..87562d4bf30c 100644 --- a/src/common/interop/keyboard_layout.cpp +++ b/src/common/interop/keyboard_layout.cpp @@ -56,7 +56,7 @@ bool mapKeycodeToUnicode(const int vCode, HKL layout, const BYTE* keyState, std: const UINT scanCode = MapVirtualKeyExW(vCode, MAPVK_VK_TO_VSC, layout); // Get the unicode representation from the virtual key code and scan code pair const UINT wFlags = 1 << 2; // If bit 2 is set, keyboard state is not changed (Windows 10, version 1607 and newer) - const int result = ToUnicodeEx(vCode, scanCode, keyState, outBuffer.data(), (int)outBuffer.size(), wFlags, layout); + const int result = ToUnicodeEx(vCode, scanCode, keyState, outBuffer.data(), static_cast(outBuffer.size()), wFlags, layout); return result != 0; } diff --git a/src/common/interop/two_way_pipe_message_ipc.cpp b/src/common/interop/two_way_pipe_message_ipc.cpp index 69215665c724..7dd1dedf36aa 100644 --- a/src/common/interop/two_way_pipe_message_ipc.cpp +++ b/src/common/interop/two_way_pipe_message_ipc.cpp @@ -184,9 +184,9 @@ BOOL TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::GetLogonSID(HANDLE hToken, if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto Cleanup; - ptg = (PTOKEN_GROUPS)HeapAlloc(GetProcessHeap(), + ptg = static_cast(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, - dwLength); + dwLength)); if (ptg == NULL) goto Cleanup; @@ -213,14 +213,14 @@ BOOL TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::GetLogonSID(HANDLE hToken, // Found the logon SID; make a copy of it. dwLength = GetLengthSid(ptg->Groups[dwIndex].Sid); - *ppsid = (PSID)HeapAlloc(GetProcessHeap(), + *ppsid = static_cast(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, - dwLength); + dwLength)); if (*ppsid == NULL) goto Cleanup; if (!CopySid(dwLength, *ppsid, ptg->Groups[dwIndex].Sid)) { - HeapFree(GetProcessHeap(), 0, (LPVOID)*ppsid); + HeapFree(GetProcessHeap(), 0, static_cast(*ppsid)); goto Cleanup; } break; @@ -233,7 +233,7 @@ BOOL TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::GetLogonSID(HANDLE hToken, // Free the buffer for the token groups. if (ptg != NULL) - HeapFree(GetProcessHeap(), 0, (LPVOID)ptg); + HeapFree(GetProcessHeap(), 0, static_cast(ptg)); return bSuccess; } @@ -241,7 +241,7 @@ BOOL TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::GetLogonSID(HANDLE hToken, VOID TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::FreeLogonSID(PSID* ppsid) { // From https://learn.microsoft.com/previous-versions/aa446670(v=vs.85) - HeapFree(GetProcessHeap(), 0, (LPVOID)*ppsid); + HeapFree(GetProcessHeap(), 0, static_cast(*ppsid)); } int TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::change_pipe_security_allow_restricted_token(HANDLE handle, HANDLE token) @@ -279,7 +279,7 @@ int TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::change_pipe_security_allow_r ea.grfInheritance = NO_INHERITANCE; ea.Trustee.TrusteeForm = TRUSTEE_IS_SID; ea.Trustee.TrusteeType = TRUSTEE_IS_USER; - ea.Trustee.ptstrName = (LPTSTR)user_restricted; + ea.Trustee.ptstrName = static_cast(user_restricted); if (SetEntriesInAcl(1, &ea, old_dacl, &new_dacl)) { @@ -302,9 +302,9 @@ int TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::change_pipe_security_allow_r error = 0; Lclean_dacl: - LocalFree((HLOCAL)new_dacl); + LocalFree(static_cast(new_dacl)); Lclean_sd: - LocalFree((HLOCAL)sd); + LocalFree(static_cast(sd)); Lclean_sid: FreeLogonSID(&user_restricted); Ldone: diff --git a/src/common/utils/HDropIterator.h b/src/common/utils/HDropIterator.h index 3b52d65babf1..11ffab5863d4 100644 --- a/src/common/utils/HDropIterator.h +++ b/src/common/utils/HDropIterator.h @@ -19,7 +19,7 @@ class HDropIterator if (SUCCEEDED(pDataObject->GetData(&formatetc, &m_medium))) { - _listCount = DragQueryFile((HDROP)m_medium.hGlobal, 0xFFFFFFFF, NULL, 0); + _listCount = DragQueryFile(static_cast(m_medium.hGlobal), 0xFFFFFFFF, NULL, 0); } else { @@ -52,10 +52,10 @@ class HDropIterator LPTSTR CurrentItem() const { - UINT cch = DragQueryFile((HDROP)m_medium.hGlobal, _current, NULL, 0) + 1; - LPTSTR pszPath = (LPTSTR)malloc(sizeof(TCHAR) * cch); + UINT cch = DragQueryFile(static_cast(m_medium.hGlobal), _current, NULL, 0) + 1; + LPTSTR pszPath = static_cast(malloc(sizeof(TCHAR) * cch)); - DragQueryFile((HDROP)m_medium.hGlobal, _current, pszPath, cch); + DragQueryFile(static_cast(m_medium.hGlobal), _current, pszPath, cch); return pszPath; } diff --git a/src/common/utils/HttpClient.h b/src/common/utils/HttpClient.h index 86b201a5d1db..8726368fbbde 100644 --- a/src/common/utils/HttpClient.h +++ b/src/common/utils/HttpClient.h @@ -57,7 +57,7 @@ namespace http totalBytesRead += buffer.Length(); if (progressUpdateCallback) { - float percentage = (float)totalBytesRead / totalBytes; + float percentage = static_cast(totalBytesRead) / totalBytes; progressUpdateCallback(percentage); } diff --git a/src/common/utils/UnhandledExceptionHandler.h b/src/common/utils/UnhandledExceptionHandler.h index a3a69b29328f..bbe2e81f2488 100644 --- a/src/common/utils/UnhandledExceptionHandler.h +++ b/src/common/utils/UnhandledExceptionHandler.h @@ -93,7 +93,7 @@ inline std::wstring GetModuleName(HANDLE process, const STACKFRAME64& stack) return std::wstring(); } - if (!GetModuleFileNameW((HINSTANCE)moduleBase, modulePath, MAX_PATH)) + if (!GetModuleFileNameW(reinterpret_cast(moduleBase), modulePath, MAX_PATH)) { Logger::error(L"Failed to get a module path. {}", get_last_error_or_default(GetLastError())); return std::wstring(); @@ -105,7 +105,7 @@ inline std::wstring GetModuleName(HANDLE process, const STACKFRAME64& stack) inline std::wstring GetName(HANDLE process, const STACKFRAME64& stack) { - static IMAGEHLP_SYMBOL64* pSymbol = (IMAGEHLP_SYMBOL64*)malloc(sizeof(IMAGEHLP_SYMBOL64) + MAX_PATH * sizeof(TCHAR)); + static IMAGEHLP_SYMBOL64* pSymbol = static_cast(malloc(sizeof(IMAGEHLP_SYMBOL64) + MAX_PATH * sizeof(TCHAR))); if (!pSymbol) { return std::wstring(); diff --git a/src/common/utils/elevation.h b/src/common/utils/elevation.h index 2615d4b8ad98..bad925c4e944 100644 --- a/src/common/utils/elevation.h +++ b/src/common/utils/elevation.h @@ -198,7 +198,7 @@ inline bool drop_elevated_privileges() TOKEN_MANDATORY_LABEL label = { 0 }; label.Label.Attributes = SE_GROUP_INTEGRITY; label.Label.Sid = medium_sid; - DWORD size = (DWORD)sizeof(TOKEN_MANDATORY_LABEL) + ::GetLengthSid(medium_sid); + DWORD size = static_cast(sizeof(TOKEN_MANDATORY_LABEL) + ::GetLengthSid(medium_sid)); BOOL result = SetTokenInformation(token, TokenIntegrityLevel, &label, size); LocalFree(medium_sid); @@ -464,7 +464,7 @@ inline bool check_user_is_admin() } // Allocate the buffer. - pGroupInfo = (PTOKEN_GROUPS)GlobalAlloc(GPTR, dwSize); + pGroupInfo = static_cast(GlobalAlloc(GPTR, dwSize)); // Call GetTokenInformation again to get the group information. if (!GetTokenInformation(hToken, TokenGroups, pGroupInfo, dwSize, &dwSize)) diff --git a/src/common/utils/gpo.h b/src/common/utils/gpo.h index c77c036c51ba..6c02e2b159d2 100644 --- a/src/common/utils/gpo.h +++ b/src/common/utils/gpo.h @@ -50,7 +50,7 @@ namespace powertoys_gpo { inline gpo_rule_configured_t getConfiguredValue(const std::wstring& registry_value_name) { HKEY key{}; - DWORD value = (DWORD) -2; + DWORD value = 0xFFFFFFFE; DWORD valueSize = sizeof(value); bool machine_key_found = true; @@ -62,7 +62,7 @@ namespace powertoys_gpo { if(machine_key_found) { // If the path was found in the machine, we need to check if the value for the policy exists. - auto res = RegQueryValueExW(key, registry_value_name.c_str(), nullptr, nullptr, (LPBYTE)&value, &valueSize); + auto res = RegQueryValueExW(key, registry_value_name.c_str(), nullptr, nullptr, reinterpret_cast(&value), &valueSize); RegCloseKey(key); @@ -82,7 +82,7 @@ namespace powertoys_gpo { } return gpo_rule_configured_unavailable; } - auto res = RegQueryValueExW(key, registry_value_name.c_str(), nullptr, nullptr, (LPBYTE)&value, &valueSize); + auto res = RegQueryValueExW(key, registry_value_name.c_str(), nullptr, nullptr, reinterpret_cast(&value), &valueSize); RegCloseKey(key); if (res != ERROR_SUCCESS) { diff --git a/src/common/utils/process_path.h b/src/common/utils/process_path.h index 382a1d2ea59f..56129a9bb749 100644 --- a/src/common/utils/process_path.h +++ b/src/common/utils/process_path.h @@ -15,7 +15,7 @@ inline std::wstring get_process_path(DWORD pid) noexcept { name.resize(MAX_PATH); DWORD name_length = static_cast(name.length()); - if (QueryFullProcessImageNameW(process, 0, (LPWSTR)name.data(), &name_length) == 0) + if (QueryFullProcessImageNameW(process, 0, name.data(), &name_length) == 0) { name_length = 0; } @@ -118,5 +118,5 @@ inline std::wstring get_module_folderpath(HMODULE mod = nullptr, const bool remo { PathRemoveFileSpecW(buffer); } - return { buffer, (UINT)lstrlenW(buffer) }; + return { buffer, static_cast(lstrlenW(buffer))}; } diff --git a/src/common/utils/registry.h b/src/common/utils/registry.h index d25445799983..fbb44a23f5ec 100644 --- a/src/common/utils/registry.h +++ b/src/common/utils/registry.h @@ -241,7 +241,7 @@ namespace registry switch (type) { case REG_DWORD: - return *(DWORD*)buffer; + return *reinterpret_cast(buffer); case REG_SZ: { if (!valueSize) diff --git a/src/common/utils/timeutil.h b/src/common/utils/timeutil.h index 8242cef9d031..b82e7981bdc4 100644 --- a/src/common/utils/timeutil.h +++ b/src/common/utils/timeutil.h @@ -60,7 +60,7 @@ namespace timeutil inline int64_t in_days(const std::time_t to, const std::time_t from) { - return static_cast(std::difftime(to, from) / (3600 * (int64_t)24)); + return static_cast(std::difftime(to, from) / (3600 * 24LL)); } } } diff --git a/src/common/utils/winapi_error.h b/src/common/utils/winapi_error.h index b4cc01aa8332..dec9f93146e6 100644 --- a/src/common/utils/winapi_error.h +++ b/src/common/utils/winapi_error.h @@ -35,7 +35,7 @@ inline void show_last_error_message(const wchar_t* functionName, DWORD dw, const { return; } - LPWSTR lpDisplayBuf = (LPWSTR)LocalAlloc(LMEM_ZEROINIT, (system_message->size() + lstrlenW(functionName) + 40) * sizeof(WCHAR)); + LPWSTR lpDisplayBuf = static_cast(LocalAlloc(LMEM_ZEROINIT, (system_message->size() + lstrlenW(functionName) + 40) * sizeof(WCHAR))); if (lpDisplayBuf != NULL) { StringCchPrintfW(lpDisplayBuf, @@ -44,7 +44,7 @@ inline void show_last_error_message(const wchar_t* functionName, DWORD dw, const functionName, system_message->c_str(), dw); - MessageBoxW(NULL, (LPCTSTR)lpDisplayBuf, errorTitle, MB_OK | MB_ICONERROR); + MessageBoxW(NULL, lpDisplayBuf, errorTitle, MB_OK | MB_ICONERROR); LocalFree(lpDisplayBuf); } } diff --git a/src/common/utils/window.h b/src/common/utils/window.h index 36e4b671c327..cfcf20534ac0 100644 --- a/src/common/utils/window.h +++ b/src/common/utils/window.h @@ -60,7 +60,7 @@ template inline T GetWindowCreateParam(LPARAM lparam) { static_assert(sizeof(T) <= sizeof(void*)); - T data{ (T)(reinterpret_cast(lparam)->lpCreateParams) }; + T data{ static_cast (reinterpret_cast(lparam)->lpCreateParams) }; return data; } @@ -74,5 +74,5 @@ inline void StoreWindowParam(HWND window, T data) template inline T GetWindowParam(HWND window) { - return (T)GetWindowLongPtrW(window, GWLP_USERDATA); + return reinterpret_cast (GetWindowLongPtrW(window, GWLP_USERDATA)); }