mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
[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:
@@ -19,7 +19,7 @@ public:
|
||||
|
||||
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
|
||||
{
|
||||
@@ -52,10 +52,10 @@ public:
|
||||
|
||||
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<HDROP>(m_medium.hGlobal), _current, NULL, 0) + 1;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace http
|
||||
totalBytesRead += buffer.Length();
|
||||
if (progressUpdateCallback)
|
||||
{
|
||||
float percentage = (float)totalBytesRead / totalBytes;
|
||||
float percentage = static_cast<float>(totalBytesRead) / totalBytes;
|
||||
progressUpdateCallback(percentage);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<HINSTANCE>(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<IMAGEHLP_SYMBOL64*>(malloc(sizeof(IMAGEHLP_SYMBOL64) + MAX_PATH * sizeof(TCHAR)));
|
||||
if (!pSymbol)
|
||||
{
|
||||
return std::wstring();
|
||||
|
||||
@@ -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<DWORD>(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<PTOKEN_GROUPS>(GlobalAlloc(GPTR, dwSize));
|
||||
|
||||
// Call GetTokenInformation again to get the group information.
|
||||
if (!GetTokenInformation(hToken, TokenGroups, pGroupInfo, dwSize, &dwSize))
|
||||
|
||||
@@ -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<LPBYTE>(&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<LPBYTE>(&value), &valueSize);
|
||||
RegCloseKey(key);
|
||||
|
||||
if (res != ERROR_SUCCESS) {
|
||||
|
||||
@@ -15,7 +15,7 @@ inline std::wstring get_process_path(DWORD pid) noexcept
|
||||
{
|
||||
name.resize(MAX_PATH);
|
||||
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;
|
||||
}
|
||||
@@ -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<uint64_t>(lstrlenW(buffer))};
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ namespace registry
|
||||
switch (type)
|
||||
{
|
||||
case REG_DWORD:
|
||||
return *(DWORD*)buffer;
|
||||
return *reinterpret_cast<const DWORD*>(buffer);
|
||||
case REG_SZ:
|
||||
{
|
||||
if (!valueSize)
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace timeutil
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<LPWSTR>(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ template<typename T>
|
||||
inline T GetWindowCreateParam(LPARAM lparam)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -74,5 +74,5 @@ inline void StoreWindowParam(HWND window, T data)
|
||||
template<typename T>
|
||||
inline T GetWindowParam(HWND window)
|
||||
{
|
||||
return (T)GetWindowLongPtrW(window, GWLP_USERDATA);
|
||||
return reinterpret_cast <T>(GetWindowLongPtrW(window, GWLP_USERDATA));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user