[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
This commit is contained in:
sosssego 2023-02-08 11:00:19 +00:00 committed by GitHub
parent 956eb98125
commit a743e496c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 66 additions and 69 deletions

View File

@ -6,110 +6,110 @@ namespace winrt::PowerToys::GPOWrapper::implementation
{ {
GpoRuleConfigured GPOWrapper::GetConfiguredAlwaysOnTopEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredAlwaysOnTopEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredAlwaysOnTopEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredAlwaysOnTopEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredAwakeEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredAwakeEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredAwakeEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredAwakeEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredColorPickerEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredColorPickerEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredColorPickerEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredColorPickerEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredFancyZonesEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredFancyZonesEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredFancyZonesEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredFancyZonesEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredFileLocksmithEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredFileLocksmithEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredFileLocksmithEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredFileLocksmithEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredSvgPreviewEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredSvgPreviewEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredSvgPreviewEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredSvgPreviewEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredMarkdownPreviewEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredMarkdownPreviewEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredMarkdownPreviewEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredMarkdownPreviewEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredMonacoPreviewEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredMonacoPreviewEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredMonacoPreviewEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredMonacoPreviewEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredPdfPreviewEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredPdfPreviewEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredPdfPreviewEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredPdfPreviewEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredGcodePreviewEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredGcodePreviewEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredGcodePreviewEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredGcodePreviewEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredSvgThumbnailsEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredSvgThumbnailsEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredSvgThumbnailsEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredSvgThumbnailsEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredPdfThumbnailsEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredPdfThumbnailsEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredPdfThumbnailsEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredPdfThumbnailsEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredGcodeThumbnailsEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredGcodeThumbnailsEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredGcodeThumbnailsEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredGcodeThumbnailsEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredStlThumbnailsEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredStlThumbnailsEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredStlThumbnailsEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredStlThumbnailsEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredHostsFileEditorEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredHostsFileEditorEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredHostsFileEditorEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredHostsFileEditorEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredImageResizerEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredImageResizerEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredImageResizerEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredImageResizerEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredKeyboardManagerEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredKeyboardManagerEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredKeyboardManagerEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredKeyboardManagerEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredFindMyMouseEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredFindMyMouseEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredFindMyMouseEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredFindMyMouseEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredMouseHighlighterEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredMouseHighlighterEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredMouseHighlighterEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredMouseHighlighterEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredMousePointerCrosshairsEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredMousePointerCrosshairsEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredMousePointerCrosshairsEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredMousePointerCrosshairsEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredPowerRenameEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredPowerRenameEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredPowerRenameEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredPowerRenameEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredPowerLauncherEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredPowerLauncherEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredPowerLauncherEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredPowerLauncherEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredQuickAccentEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredQuickAccentEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredQuickAccentEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredQuickAccentEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredScreenRulerEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredScreenRulerEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredScreenRulerEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredScreenRulerEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredShortcutGuideEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredShortcutGuideEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredShortcutGuideEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredShortcutGuideEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredTextExtractorEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredTextExtractorEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredTextExtractorEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredTextExtractorEnabledValue());
} }
GpoRuleConfigured GPOWrapper::GetConfiguredVideoConferenceMuteEnabledValue() GpoRuleConfigured GPOWrapper::GetConfiguredVideoConferenceMuteEnabledValue()
{ {
return (GpoRuleConfigured)powertoys_gpo::getConfiguredVideoConferenceMuteEnabledValue(); return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredVideoConferenceMuteEnabledValue());
} }
} }

View File

@ -247,7 +247,7 @@ namespace PowerToysSettings
bool Settings::serialize_to_buffer(wchar_t* buffer, int* buffer_size) bool Settings::serialize_to_buffer(wchar_t* buffer, int* buffer_size)
{ {
auto result = m_json.Stringify(); auto result = m_json.Stringify();
const int result_len = (int)result.size() + 1; const int result_len = static_cast<int>(result.size() + 1);
if (buffer == nullptr || *buffer_size < result_len) if (buffer == nullptr || *buffer_size < result_len)
{ {

View File

@ -220,7 +220,7 @@ namespace PowerToysSettings
std::array<BYTE, 256> key_states{}; // Zero-initialize std::array<BYTE, 256> key_states{}; // Zero-initialize
std::array<wchar_t, 256> output; std::array<wchar_t, 256> output;
const UINT wFlags = 1 << 2; // If bit 2 is set, keyboard state is not changed (Windows 10, version 1607 and newer) 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<int>(output.size()) - 1, wFlags, layout);
if (output_bytes <= 0) if (output_bytes <= 0)
{ {
// If ToUnicodeEx fails (e.g. for F1-F12 keys) use GetKeyNameTextW // If ToUnicodeEx fails (e.g. for F1-F12 keys) use GetKeyNameTextW

View File

@ -14,7 +14,7 @@ HRESULT GetIconIndexFromPath(_In_ PCWSTR path, _Out_ int* index)
if (!PathIsRelative(path)) if (!PathIsRelative(path))
{ {
DWORD attrib = GetFileAttributes(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) if (himl)
{ {
*index = shFileInfo.iIcon; *index = shFileInfo.iIcon;
@ -61,14 +61,14 @@ HBITMAP CreateBitmapFromIcon(_In_ HICON hIcon, _In_opt_ UINT width, _In_opt_ UIN
if (hBitmap != NULL) if (hBitmap != NULL)
{ {
// Select bitmap into DC // Select bitmap into DC
HBITMAP hBitmapOld = (HBITMAP)SelectObject(hDC, hBitmap); HBITMAP hBitmapOld = static_cast<HBITMAP>(SelectObject(hDC, hBitmap));
if (hBitmapOld != NULL) if (hBitmapOld != NULL)
{ {
// Draw icon into DC // Draw icon into DC
if (DrawIconEx(hDC, 0, 0, hIcon, rc.right, rc.bottom, 0, NULL, DI_NORMAL)) if (DrawIconEx(hDC, 0, 0, hIcon, rc.right, rc.bottom, 0, NULL, DI_NORMAL))
{ {
// Restore original bitmap in DC // Restore original bitmap in DC
hBitmapResult = (HBITMAP)SelectObject(hDC, hBitmapOld); hBitmapResult = static_cast<HBITMAP>(SelectObject(hDC, hBitmapOld));
hBitmapOld = NULL; hBitmapOld = NULL;
hBitmap = NULL; hBitmap = NULL;
} }

View File

@ -28,10 +28,7 @@ AppTheme ThemeHelpers::GetAppTheme()
} }
// convert bytes written to our buffer to an int, assuming little-endian // convert bytes written to our buffer to an int, assuming little-endian
auto i = int(buffer[3] << 24 | auto i = static_cast<int>(buffer[3] << 24 | buffer[2] << 16 | buffer[1] << 8 | buffer[0]);
buffer[2] << 16 |
buffer[1] << 8 |
buffer[0]);
return AppTheme(i); return AppTheme(i);
} }

View File

@ -8,7 +8,7 @@
#pragma warning(disable : 4702) #pragma warning(disable : 4702)
DWORD WINAPI _checkTheme(LPVOID lpParam) DWORD WINAPI _checkTheme(LPVOID lpParam)
{ {
auto listener = (ThemeListener*)lpParam; auto listener = static_cast<ThemeListener*>(lpParam);
listener->CheckTheme(); listener->CheckTheme();
return 0; return 0;
} }

View File

@ -11,7 +11,7 @@ DWORD WindowsColors::rgb_color(DWORD abgr_color)
} }
DWORD WindowsColors::rgb_color(winrt::Windows::UI::Color 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<DWORD>((color.R << 16) | (color.G << 8) | (color.B));
} }
WindowsColors::Color WindowsColors::get_button_face_color() WindowsColors::Color WindowsColors::get_button_face_color()
{ {

View File

@ -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); const UINT scanCode = MapVirtualKeyExW(vCode, MAPVK_VK_TO_VSC, layout);
// Get the unicode representation from the virtual key code and scan code pair // 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 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<int>(outBuffer.size()), wFlags, layout);
return result != 0; return result != 0;
} }

View File

@ -184,9 +184,9 @@ BOOL TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::GetLogonSID(HANDLE hToken,
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
goto Cleanup; goto Cleanup;
ptg = (PTOKEN_GROUPS)HeapAlloc(GetProcessHeap(), ptg = static_cast<PTOKEN_GROUPS>(HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
dwLength); dwLength));
if (ptg == NULL) if (ptg == NULL)
goto Cleanup; goto Cleanup;
@ -213,14 +213,14 @@ BOOL TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::GetLogonSID(HANDLE hToken,
// Found the logon SID; make a copy of it. // Found the logon SID; make a copy of it.
dwLength = GetLengthSid(ptg->Groups[dwIndex].Sid); dwLength = GetLengthSid(ptg->Groups[dwIndex].Sid);
*ppsid = (PSID)HeapAlloc(GetProcessHeap(), *ppsid = static_cast<PSID>(HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
dwLength); dwLength));
if (*ppsid == NULL) if (*ppsid == NULL)
goto Cleanup; goto Cleanup;
if (!CopySid(dwLength, *ppsid, ptg->Groups[dwIndex].Sid)) if (!CopySid(dwLength, *ppsid, ptg->Groups[dwIndex].Sid))
{ {
HeapFree(GetProcessHeap(), 0, (LPVOID)*ppsid); HeapFree(GetProcessHeap(), 0, static_cast<LPVOID>(*ppsid));
goto Cleanup; goto Cleanup;
} }
break; break;
@ -233,7 +233,7 @@ Cleanup:
// Free the buffer for the token groups. // Free the buffer for the token groups.
if (ptg != NULL) if (ptg != NULL)
HeapFree(GetProcessHeap(), 0, (LPVOID)ptg); HeapFree(GetProcessHeap(), 0, static_cast<LPVOID>(ptg));
return bSuccess; return bSuccess;
} }
@ -241,7 +241,7 @@ Cleanup:
VOID TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::FreeLogonSID(PSID* ppsid) VOID TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::FreeLogonSID(PSID* ppsid)
{ {
// From https://learn.microsoft.com/previous-versions/aa446670(v=vs.85) // From https://learn.microsoft.com/previous-versions/aa446670(v=vs.85)
HeapFree(GetProcessHeap(), 0, (LPVOID)*ppsid); HeapFree(GetProcessHeap(), 0, static_cast<LPVOID>(*ppsid));
} }
int TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::change_pipe_security_allow_restricted_token(HANDLE handle, HANDLE token) 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.grfInheritance = NO_INHERITANCE;
ea.Trustee.TrusteeForm = TRUSTEE_IS_SID; ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea.Trustee.TrusteeType = TRUSTEE_IS_USER; ea.Trustee.TrusteeType = TRUSTEE_IS_USER;
ea.Trustee.ptstrName = (LPTSTR)user_restricted; ea.Trustee.ptstrName = static_cast<LPTSTR>(user_restricted);
if (SetEntriesInAcl(1, &ea, old_dacl, &new_dacl)) if (SetEntriesInAcl(1, &ea, old_dacl, &new_dacl))
{ {
@ -302,9 +302,9 @@ int TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::change_pipe_security_allow_r
error = 0; error = 0;
Lclean_dacl: Lclean_dacl:
LocalFree((HLOCAL)new_dacl); LocalFree(static_cast<HLOCAL>(new_dacl));
Lclean_sd: Lclean_sd:
LocalFree((HLOCAL)sd); LocalFree(static_cast<HLOCAL>(sd));
Lclean_sid: Lclean_sid:
FreeLogonSID(&user_restricted); FreeLogonSID(&user_restricted);
Ldone: Ldone:

View File

@ -19,7 +19,7 @@ public:
if (SUCCEEDED(pDataObject->GetData(&formatetc, &m_medium))) if (SUCCEEDED(pDataObject->GetData(&formatetc, &m_medium)))
{ {
_listCount = DragQueryFile((HDROP)m_medium.hGlobal, 0xFFFFFFFF, NULL, 0); _listCount = DragQueryFile(static_cast<HDROP>(m_medium.hGlobal), 0xFFFFFFFF, NULL, 0);
} }
else else
{ {
@ -52,10 +52,10 @@ public:
LPTSTR CurrentItem() const LPTSTR CurrentItem() const
{ {
UINT cch = DragQueryFile((HDROP)m_medium.hGlobal, _current, NULL, 0) + 1; UINT cch = DragQueryFile(static_cast<HDROP>(m_medium.hGlobal), _current, NULL, 0) + 1;
LPTSTR pszPath = (LPTSTR)malloc(sizeof(TCHAR) * cch); LPTSTR pszPath = static_cast<LPTSTR>(malloc(sizeof(TCHAR) * cch));
DragQueryFile((HDROP)m_medium.hGlobal, _current, pszPath, cch); DragQueryFile(static_cast<HDROP>(m_medium.hGlobal), _current, pszPath, cch);
return pszPath; return pszPath;
} }

View File

@ -57,7 +57,7 @@ namespace http
totalBytesRead += buffer.Length(); totalBytesRead += buffer.Length();
if (progressUpdateCallback) if (progressUpdateCallback)
{ {
float percentage = (float)totalBytesRead / totalBytes; float percentage = static_cast<float>(totalBytesRead) / totalBytes;
progressUpdateCallback(percentage); progressUpdateCallback(percentage);
} }

View File

@ -93,7 +93,7 @@ inline std::wstring GetModuleName(HANDLE process, const STACKFRAME64& stack)
return std::wstring(); return std::wstring();
} }
if (!GetModuleFileNameW((HINSTANCE)moduleBase, modulePath, MAX_PATH)) if (!GetModuleFileNameW(reinterpret_cast<HINSTANCE>(moduleBase), modulePath, MAX_PATH))
{ {
Logger::error(L"Failed to get a module path. {}", get_last_error_or_default(GetLastError())); Logger::error(L"Failed to get a module path. {}", get_last_error_or_default(GetLastError()));
return std::wstring(); 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) 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<IMAGEHLP_SYMBOL64*>(malloc(sizeof(IMAGEHLP_SYMBOL64) + MAX_PATH * sizeof(TCHAR)));
if (!pSymbol) if (!pSymbol)
{ {
return std::wstring(); return std::wstring();

View File

@ -198,7 +198,7 @@ inline bool drop_elevated_privileges()
TOKEN_MANDATORY_LABEL label = { 0 }; TOKEN_MANDATORY_LABEL label = { 0 };
label.Label.Attributes = SE_GROUP_INTEGRITY; label.Label.Attributes = SE_GROUP_INTEGRITY;
label.Label.Sid = medium_sid; label.Label.Sid = medium_sid;
DWORD size = (DWORD)sizeof(TOKEN_MANDATORY_LABEL) + ::GetLengthSid(medium_sid); DWORD size = static_cast<DWORD>(sizeof(TOKEN_MANDATORY_LABEL) + ::GetLengthSid(medium_sid));
BOOL result = SetTokenInformation(token, TokenIntegrityLevel, &label, size); BOOL result = SetTokenInformation(token, TokenIntegrityLevel, &label, size);
LocalFree(medium_sid); LocalFree(medium_sid);
@ -464,7 +464,7 @@ inline bool check_user_is_admin()
} }
// Allocate the buffer. // Allocate the buffer.
pGroupInfo = (PTOKEN_GROUPS)GlobalAlloc(GPTR, dwSize); pGroupInfo = static_cast<PTOKEN_GROUPS>(GlobalAlloc(GPTR, dwSize));
// Call GetTokenInformation again to get the group information. // Call GetTokenInformation again to get the group information.
if (!GetTokenInformation(hToken, TokenGroups, pGroupInfo, dwSize, &dwSize)) if (!GetTokenInformation(hToken, TokenGroups, pGroupInfo, dwSize, &dwSize))

View File

@ -50,7 +50,7 @@ namespace powertoys_gpo {
inline gpo_rule_configured_t getConfiguredValue(const std::wstring& registry_value_name) inline gpo_rule_configured_t getConfiguredValue(const std::wstring& registry_value_name)
{ {
HKEY key{}; HKEY key{};
DWORD value = (DWORD) -2; DWORD value = 0xFFFFFFFE;
DWORD valueSize = sizeof(value); DWORD valueSize = sizeof(value);
bool machine_key_found = true; bool machine_key_found = true;
@ -62,7 +62,7 @@ namespace powertoys_gpo {
if(machine_key_found) if(machine_key_found)
{ {
// If the path was found in the machine, we need to check if the value for the policy exists. // 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<LPBYTE>(&value), &valueSize);
RegCloseKey(key); RegCloseKey(key);
@ -82,7 +82,7 @@ namespace powertoys_gpo {
} }
return gpo_rule_configured_unavailable; 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<LPBYTE>(&value), &valueSize);
RegCloseKey(key); RegCloseKey(key);
if (res != ERROR_SUCCESS) { if (res != ERROR_SUCCESS) {

View File

@ -15,7 +15,7 @@ inline std::wstring get_process_path(DWORD pid) noexcept
{ {
name.resize(MAX_PATH); name.resize(MAX_PATH);
DWORD name_length = static_cast<DWORD>(name.length()); DWORD name_length = static_cast<DWORD>(name.length());
if (QueryFullProcessImageNameW(process, 0, (LPWSTR)name.data(), &name_length) == 0) if (QueryFullProcessImageNameW(process, 0, name.data(), &name_length) == 0)
{ {
name_length = 0; name_length = 0;
} }
@ -118,5 +118,5 @@ inline std::wstring get_module_folderpath(HMODULE mod = nullptr, const bool remo
{ {
PathRemoveFileSpecW(buffer); PathRemoveFileSpecW(buffer);
} }
return { buffer, (UINT)lstrlenW(buffer) }; return { buffer, static_cast<uint64_t>(lstrlenW(buffer))};
} }

View File

@ -241,7 +241,7 @@ namespace registry
switch (type) switch (type)
{ {
case REG_DWORD: case REG_DWORD:
return *(DWORD*)buffer; return *reinterpret_cast<const DWORD*>(buffer);
case REG_SZ: case REG_SZ:
{ {
if (!valueSize) if (!valueSize)

View File

@ -60,7 +60,7 @@ namespace timeutil
inline int64_t in_days(const std::time_t to, const std::time_t from) inline int64_t in_days(const std::time_t to, const std::time_t from)
{ {
return static_cast<int64_t>(std::difftime(to, from) / (3600 * (int64_t)24)); return static_cast<int64_t>(std::difftime(to, from) / (3600 * 24LL));
} }
} }
} }

View File

@ -35,7 +35,7 @@ inline void show_last_error_message(const wchar_t* functionName, DWORD dw, const
{ {
return; return;
} }
LPWSTR lpDisplayBuf = (LPWSTR)LocalAlloc(LMEM_ZEROINIT, (system_message->size() + lstrlenW(functionName) + 40) * sizeof(WCHAR)); LPWSTR lpDisplayBuf = static_cast<LPWSTR>(LocalAlloc(LMEM_ZEROINIT, (system_message->size() + lstrlenW(functionName) + 40) * sizeof(WCHAR)));
if (lpDisplayBuf != NULL) if (lpDisplayBuf != NULL)
{ {
StringCchPrintfW(lpDisplayBuf, StringCchPrintfW(lpDisplayBuf,
@ -44,7 +44,7 @@ inline void show_last_error_message(const wchar_t* functionName, DWORD dw, const
functionName, functionName,
system_message->c_str(), system_message->c_str(),
dw); dw);
MessageBoxW(NULL, (LPCTSTR)lpDisplayBuf, errorTitle, MB_OK | MB_ICONERROR); MessageBoxW(NULL, lpDisplayBuf, errorTitle, MB_OK | MB_ICONERROR);
LocalFree(lpDisplayBuf); LocalFree(lpDisplayBuf);
} }
} }

View File

@ -60,7 +60,7 @@ template<typename T>
inline T GetWindowCreateParam(LPARAM lparam) inline T GetWindowCreateParam(LPARAM lparam)
{ {
static_assert(sizeof(T) <= sizeof(void*)); static_assert(sizeof(T) <= sizeof(void*));
T data{ (T)(reinterpret_cast<CREATESTRUCT*>(lparam)->lpCreateParams) }; T data{ static_cast <T>(reinterpret_cast<CREATESTRUCT*>(lparam)->lpCreateParams) };
return data; return data;
} }
@ -74,5 +74,5 @@ inline void StoreWindowParam(HWND window, T data)
template<typename T> template<typename T>
inline T GetWindowParam(HWND window) inline T GetWindowParam(HWND window)
{ {
return (T)GetWindowLongPtrW(window, GWLP_USERDATA); return reinterpret_cast <T>(GetWindowLongPtrW(window, GWLP_USERDATA));
} }