[Analyzers][CPP]Changes to fix warning 26493 on src/modules/ (P) (#23604)

* Changes to fix warning 26493 on src/modules/
This commit is contained in:
sosssego 2023-02-08 13:10:28 +00:00 коммит произвёл GitHub
Родитель 17475ec705
Коммит c7f761a589
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 29 добавлений и 23 удалений

Просмотреть файл

@ -94,7 +94,7 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
{ {
std::vector<std::wstring> excludedApps; std::vector<std::wstring> excludedApps;
auto excludedUppercase = std::wstring(excludedAppsView); auto excludedUppercase = std::wstring(excludedAppsView);
CharUpperBuffW(excludedUppercase.data(), (DWORD)excludedUppercase.length()); CharUpperBuffW(excludedUppercase.data(), static_cast<DWORD>(excludedUppercase.length()));
std::wstring_view view(excludedUppercase); std::wstring_view view(excludedUppercase);
view = left_trim<wchar_t>(trim<wchar_t>(view)); view = left_trim<wchar_t>(trim<wchar_t>(view));
@ -129,7 +129,7 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
return m_prevForegroundAppExcl.second; return m_prevForegroundAppExcl.second;
} }
auto processPath = get_process_path(foregroundApp); auto processPath = get_process_path(foregroundApp);
CharUpperBuffW(processPath.data(), (DWORD)processPath.length()); CharUpperBuffW(processPath.data(), static_cast<DWORD>(processPath.length()));
m_prevForegroundAppExcl = { foregroundApp, m_prevForegroundAppExcl = { foregroundApp,
find_app_name_in_path(processPath, m_settings.excludedApps) }; find_app_name_in_path(processPath, m_settings.excludedApps) };

Просмотреть файл

@ -213,7 +213,7 @@ private:
auto val = get_last_error_message(GetLastError()); auto val = get_last_error_message(GetLastError());
Logger::warn(L"UuidCreate can not create guid. {}", val.has_value() ? val.value() : L""); Logger::warn(L"UuidCreate can not create guid. {}", val.has_value() ? val.value() : L"");
} }
else if (UuidToString(&temp_uuid, (RPC_WSTR*)&uuid_chars) != RPC_S_OK) else if (UuidToString(&temp_uuid, reinterpret_cast<RPC_WSTR*>(& uuid_chars)) != RPC_S_OK)
{ {
auto val = get_last_error_message(GetLastError()); auto val = get_last_error_message(GetLastError());
Logger::warn(L"UuidToString can not convert to string. {}", val.has_value() ? val.value() : L""); Logger::warn(L"UuidToString can not convert to string. {}", val.has_value() ? val.value() : L"");
@ -222,7 +222,7 @@ private:
if (uuid_chars != nullptr) if (uuid_chars != nullptr)
{ {
pipe_name += std::wstring(uuid_chars); pipe_name += std::wstring(uuid_chars);
RpcStringFree((RPC_WSTR*)&uuid_chars); RpcStringFree(reinterpret_cast<RPC_WSTR*>(&uuid_chars));
uuid_chars = nullptr; uuid_chars = nullptr;
} }
create_pipe_thread = std::thread(&PowerRenameContextMenuCommand::StartNamedPipeServerAndSendData, this, pipe_name); create_pipe_thread = std::thread(&PowerRenameContextMenuCommand::StartNamedPipeServerAndSendData, this, pipe_name);

Просмотреть файл

@ -87,8 +87,8 @@ namespace winrt::PowerRenameUI::implementation
winrt::Windows::Graphics::RectInt32 rect; winrt::Windows::Graphics::RectInt32 rect;
// Scale window size // Scale window size
rect.Width = (int32_t)(width * (float)window_dpi / x_dpi); rect.Width = static_cast<int32_t>(width * static_cast<float>(window_dpi) / x_dpi);
rect.Height = (int32_t)(height * (float)window_dpi / x_dpi); rect.Height = static_cast<int32_t>(height * static_cast<float>(window_dpi) / x_dpi);
// Center to screen // Center to screen
rect.X = displayArea.WorkArea().X + displayArea.WorkArea().Width / 2 - width / 2; rect.X = displayArea.WorkArea().X + displayArea.WorkArea().Width / 2 - width / 2;
rect.Y = displayArea.WorkArea().Y + displayArea.WorkArea().Height / 2 - height / 2; rect.Y = displayArea.WorkArea().Y + displayArea.WorkArea().Height / 2 - height / 2;
@ -1070,7 +1070,7 @@ namespace winrt::PowerRenameUI::implementation
if (closeUIWindowAfterRenaming) if (closeUIWindowAfterRenaming)
{ {
// Close the window // Close the window
PostMessage(m_window, WM_CLOSE, (WPARAM)0, (LPARAM)0); PostMessage(m_window, WM_CLOSE, static_cast<WPARAM>(0), static_cast<LPARAM>(0));
} }
else else
{ {

Просмотреть файл

@ -13,7 +13,13 @@
#include <winrt/Windows.Foundation.h> #include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h> #include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.System.h> #include <winrt/Windows.System.h>
// disable warning 26493 - Don't use C-style casts
#pragma warning(push)
#pragma warning(disable: 26493)
#include <winrt/Microsoft.UI.Composition.h> #include <winrt/Microsoft.UI.Composition.h>
#pragma warning(pop)
#include <winrt/Microsoft.UI.Xaml.h> #include <winrt/Microsoft.UI.Xaml.h>
#include <winrt/Microsoft.UI.Xaml.Automation.Peers.h> #include <winrt/Microsoft.UI.Xaml.Automation.Peers.h>
#include <winrt/Microsoft.UI.Xaml.Controls.h> #include <winrt/Microsoft.UI.Xaml.Controls.h>

Просмотреть файл

@ -88,7 +88,7 @@ HRESULT CPowerRenameMenu::QueryContextMenu(HMENU hMenu, UINT index, UINT uIDFirs
if (CSettingsInstance().GetShowIconOnMenu()) if (CSettingsInstance().GetShowIconOnMenu())
{ {
HICON hIcon = (HICON)LoadImage(g_hInst, MAKEINTRESOURCE(IDI_RENAME), IMAGE_ICON, 16, 16, 0); HICON hIcon = static_cast<HICON>(LoadImage(g_hInst, MAKEINTRESOURCE(IDI_RENAME), IMAGE_ICON, 16, 16, 0));
if (hIcon) if (hIcon)
{ {
mii.fMask |= MIIM_BITMAP; mii.fMask |= MIIM_BITMAP;
@ -131,7 +131,7 @@ HRESULT CPowerRenameMenu::RunPowerRename(CMINVOKECOMMANDINFO* pici, IShellItemAr
// Set the application path based on the location of the dll // Set the application path based on the location of the dll
std::wstring path = get_module_folderpath(g_hInst); std::wstring path = get_module_folderpath(g_hInst);
path = path + L"\\PowerToys.PowerRename.exe"; path = path + L"\\PowerToys.PowerRename.exe";
LPTSTR lpApplicationName = (LPTSTR)path.c_str(); LPTSTR lpApplicationName = path.data();
// Create an anonymous pipe to stream filenames // Create an anonymous pipe to stream filenames
SECURITY_ATTRIBUTES sa; SECURITY_ATTRIBUTES sa;
HANDLE hReadPipe; HANDLE hReadPipe;

Просмотреть файл

@ -420,7 +420,7 @@ BOOL GetEnumeratedFileName(__out_ecount(cchMax) PWSTR pszUniqueName, UINT cchMax
if (!pszRest) if (!pszRest)
{ {
pszRest = PathFindExtension(pszTemplate); pszRest = PathFindExtension(pszTemplate);
cchStem = (int)(pszRest - pszTemplate); cchStem = static_cast<int>(pszRest - pszTemplate);
hr = StringCchCopy(szFormat, ARRAYSIZE(szFormat), L" (%lu)"); hr = StringCchCopy(szFormat, ARRAYSIZE(szFormat), L" (%lu)");
} }
@ -428,7 +428,7 @@ BOOL GetEnumeratedFileName(__out_ecount(cchMax) PWSTR pszUniqueName, UINT cchMax
{ {
pszRest++; pszRest++;
cchStem = (int)(pszRest - pszTemplate); cchStem = static_cast<int>(pszRest - pszTemplate);
while (*pszRest && *pszRest >= L'0' && *pszRest <= L'9') while (*pszRest && *pszRest >= L'0' && *pszRest <= L'9')
{ {
@ -581,7 +581,7 @@ HWND CreateMsgWindow(_In_ HINSTANCE hInst, _In_ WNDPROC pfnWndProc, _In_ void* p
wc.lpfnWndProc = DefWindowProc; wc.lpfnWndProc = DefWindowProc;
wc.cbWndExtra = sizeof(void*); wc.cbWndExtra = sizeof(void*);
wc.hInstance = hInst; wc.hInstance = hInst;
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1);
wc.lpszClassName = wndClassName; wc.lpszClassName = wndClassName;
RegisterClass(&wc); RegisterClass(&wc);
@ -590,10 +590,10 @@ HWND CreateMsgWindow(_In_ HINSTANCE hInst, _In_ WNDPROC pfnWndProc, _In_ void* p
0, wndClassName, nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hInst, nullptr); 0, wndClassName, nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hInst, nullptr);
if (hwnd) if (hwnd)
{ {
SetWindowLongPtr(hwnd, 0, (LONG_PTR)p); SetWindowLongPtr(hwnd, 0, reinterpret_cast<LONG_PTR>(p));
if (pfnWndProc) if (pfnWndProc)
{ {
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)pfnWndProc); SetWindowLongPtr(hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(pfnWndProc));
} }
} }

Просмотреть файл

@ -123,12 +123,12 @@ void MRUListHandler::ParseJson()
unsigned int oldSize{ size }; unsigned int oldSize{ size };
if (json::has(jsonObject, c_maxMRUSize, json::JsonValueType::Number)) if (json::has(jsonObject, c_maxMRUSize, json::JsonValueType::Number))
{ {
oldSize = (unsigned int)jsonObject.GetNamedNumber(c_maxMRUSize); oldSize = static_cast<unsigned int>(jsonObject.GetNamedNumber(c_maxMRUSize));
} }
unsigned int oldPushIdx{ 0 }; unsigned int oldPushIdx{ 0 };
if (json::has(jsonObject, c_insertionIdx, json::JsonValueType::Number)) if (json::has(jsonObject, c_insertionIdx, json::JsonValueType::Number))
{ {
oldPushIdx = (unsigned int)jsonObject.GetNamedNumber(c_insertionIdx); oldPushIdx = static_cast<unsigned int>(jsonObject.GetNamedNumber(c_insertionIdx));
if (oldPushIdx < 0 || oldPushIdx >= oldSize) if (oldPushIdx < 0 || oldPushIdx >= oldSize)
{ {
oldPushIdx = 0; oldPushIdx = 0;
@ -156,7 +156,7 @@ void MRUListHandler::ParseJson()
if (size > oldSize) if (size > oldSize)
{ {
std::reverse(std::begin(temp), std::end(temp)); std::reverse(std::begin(temp), std::end(temp));
pushIdx = (unsigned int)temp.size(); pushIdx = static_cast<unsigned int>(temp.size());
temp.resize(size); temp.resize(size);
} }
else else

Просмотреть файл

@ -526,7 +526,7 @@ LRESULT CALLBACK CPowerRenameManager::s_msgWndProc(_In_ HWND hwnd, _In_ UINT uMs
{ {
LRESULT lRes = 0; LRESULT lRes = 0;
CPowerRenameManager* pThis = (CPowerRenameManager*)GetWindowLongPtr(hwnd, 0); CPowerRenameManager* pThis = reinterpret_cast<CPowerRenameManager*>(GetWindowLongPtr(hwnd, 0));
if (pThis != nullptr) if (pThis != nullptr)
{ {
lRes = pThis->_WndProc(hwnd, uMsg, wParam, lParam); lRes = pThis->_WndProc(hwnd, uMsg, wParam, lParam);

Просмотреть файл

@ -125,7 +125,7 @@ void CSettings::ParseJson()
} }
if (json::has(jsonSettings, c_maxMRUSize, json::JsonValueType::Number)) if (json::has(jsonSettings, c_maxMRUSize, json::JsonValueType::Number))
{ {
settings.maxMRUSize = (unsigned int)jsonSettings.GetNamedNumber(c_maxMRUSize); settings.maxMRUSize = static_cast<unsigned int>(jsonSettings.GetNamedNumber(c_maxMRUSize));
} }
if (json::has(jsonSettings, c_searchText, json::JsonValueType::String)) if (json::has(jsonSettings, c_searchText, json::JsonValueType::String))
{ {

Просмотреть файл

@ -163,7 +163,7 @@ IFACEMETHODIMP GcodeThumbnailProvider::GetThumbnail(UINT cx, HBITMAP* phbmp, WTS
std::wstring fileNameBmp = filePath + guid + L".bmp"; std::wstring fileNameBmp = filePath + guid + L".bmp";
if (std::filesystem::exists(fileNameBmp)) if (std::filesystem::exists(fileNameBmp))
{ {
*phbmp = (HBITMAP)LoadImage(NULL, fileNameBmp.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); *phbmp = static_cast<HBITMAP>(LoadImage(NULL, fileNameBmp.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE));
*pdwAlpha = WTS_ALPHATYPE::WTSAT_ARGB; *pdwAlpha = WTS_ALPHATYPE::WTSAT_ARGB;
std::filesystem::remove(fileNameBmp); std::filesystem::remove(fileNameBmp);
} }

Просмотреть файл

@ -160,7 +160,7 @@ IFACEMETHODIMP PdfThumbnailProvider::GetThumbnail(UINT cx, HBITMAP* phbmp, WTS_A
std::wstring fileNameBmp = filePath + guid + L".bmp"; std::wstring fileNameBmp = filePath + guid + L".bmp";
if (std::filesystem::exists(fileNameBmp)) if (std::filesystem::exists(fileNameBmp))
{ {
*phbmp = (HBITMAP)LoadImage(NULL, fileNameBmp.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); *phbmp = static_cast<HBITMAP>(LoadImage(NULL, fileNameBmp.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE));
*pdwAlpha = WTS_ALPHATYPE::WTSAT_ARGB; *pdwAlpha = WTS_ALPHATYPE::WTSAT_ARGB;
std::filesystem::remove(fileNameBmp); std::filesystem::remove(fileNameBmp);
} }

Просмотреть файл

@ -160,7 +160,7 @@ IFACEMETHODIMP StlThumbnailProvider::GetThumbnail(UINT cx, HBITMAP* phbmp, WTS_A
std::wstring fileNameBmp = filePath + guid + L".bmp"; std::wstring fileNameBmp = filePath + guid + L".bmp";
if (std::filesystem::exists(fileNameBmp)) if (std::filesystem::exists(fileNameBmp))
{ {
*phbmp = (HBITMAP)LoadImage(NULL, fileNameBmp.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); *phbmp = static_cast<HBITMAP>(LoadImage(NULL, fileNameBmp.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE));
*pdwAlpha = WTS_ALPHATYPE::WTSAT_ARGB; *pdwAlpha = WTS_ALPHATYPE::WTSAT_ARGB;
std::filesystem::remove(fileNameBmp); std::filesystem::remove(fileNameBmp);
} }

Просмотреть файл

@ -161,7 +161,7 @@ IFACEMETHODIMP SvgThumbnailProvider::GetThumbnail(UINT cx, HBITMAP* phbmp, WTS_A
if (std::filesystem::exists(fileNameBmp)) if (std::filesystem::exists(fileNameBmp))
{ {
*phbmp = (HBITMAP)LoadImage(NULL, fileNameBmp.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); *phbmp = static_cast<HBITMAP>(LoadImage(NULL, fileNameBmp.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE));
*pdwAlpha = WTS_ALPHATYPE::WTSAT_ARGB; *pdwAlpha = WTS_ALPHATYPE::WTSAT_ARGB;
std::filesystem::remove(fileNameBmp); std::filesystem::remove(fileNameBmp);
} }