mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
[CodeQuality]Fix C++ static analyzer findings (#29745)
* [PVS] Fix static analyzer findings * f: fix error handling * f: more improvements * Update src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllExtensions.cpp
This commit is contained in:
@@ -3,9 +3,10 @@
|
|||||||
#ifndef PCH_H
|
#ifndef PCH_H
|
||||||
#define PCH_H
|
#define PCH_H
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 5205)
|
#pragma warning(disable : 5205)
|
||||||
#include <winrt/base.h>
|
#include <winrt/base.h>
|
||||||
#pragma warning(default : 5205)
|
#pragma warning(pop)
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _I
|
|||||||
m_reparent_event_handle = CreateEventW(nullptr, false, false, CommonSharedConstants::CROP_AND_LOCK_REPARENT_EVENT);
|
m_reparent_event_handle = CreateEventW(nullptr, false, false, CommonSharedConstants::CROP_AND_LOCK_REPARENT_EVENT);
|
||||||
m_thumbnail_event_handle = CreateEventW(nullptr, false, false, CommonSharedConstants::CROP_AND_LOCK_THUMBNAIL_EVENT);
|
m_thumbnail_event_handle = CreateEventW(nullptr, false, false, CommonSharedConstants::CROP_AND_LOCK_THUMBNAIL_EVENT);
|
||||||
m_exit_event_handle = CreateEventW(nullptr, false, false, CommonSharedConstants::CROP_AND_LOCK_EXIT_EVENT);
|
m_exit_event_handle = CreateEventW(nullptr, false, false, CommonSharedConstants::CROP_AND_LOCK_EXIT_EVENT);
|
||||||
if (!m_reparent_event_handle || !m_reparent_event_handle || !m_exit_event_handle)
|
if (!m_reparent_event_handle || !m_thumbnail_event_handle || !m_exit_event_handle)
|
||||||
{
|
{
|
||||||
Logger::warn(L"Failed to create events. {}", get_last_error_or_default(GetLastError()));
|
Logger::warn(L"Failed to create events. {}", get_last_error_or_default(GetLastError()));
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -309,9 +309,8 @@ std::wstring NtdllExtensions::pid_to_user(DWORD pid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DWORD token_size = 0;
|
DWORD token_size = 0;
|
||||||
GetTokenInformation(token, TokenUser, nullptr, 0, &token_size);
|
const bool ok = GetTokenInformation(token, TokenUser, nullptr, 0, &token_size);
|
||||||
|
if ((!ok && GetLastError() != ERROR_INSUFFICIENT_BUFFER) || !token_size)
|
||||||
if (token_size < 0)
|
|
||||||
{
|
{
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ namespace
|
|||||||
winrt::com_ptr<ID2D1Bitmap> ConvertID3D11Texture2DToD2D1Bitmap(winrt::com_ptr<ID2D1RenderTarget> rt,
|
winrt::com_ptr<ID2D1Bitmap> ConvertID3D11Texture2DToD2D1Bitmap(winrt::com_ptr<ID2D1RenderTarget> rt,
|
||||||
const MappedTextureView* capturedScreenTexture)
|
const MappedTextureView* capturedScreenTexture)
|
||||||
{
|
{
|
||||||
capturedScreenTexture->view.pixels;
|
|
||||||
|
|
||||||
D2D1_BITMAP_PROPERTIES props = { .pixelFormat = rt->GetPixelFormat() };
|
D2D1_BITMAP_PROPERTIES props = { .pixelFormat = rt->GetPixelFormat() };
|
||||||
rt->GetDpi(&props.dpiX, &props.dpiY);
|
rt->GetDpi(&props.dpiX, &props.dpiY);
|
||||||
const auto sizeF = rt->GetSize();
|
const auto sizeF = rt->GetSize();
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ void FancyZonesSettings::LoadSettings()
|
|||||||
if (auto val = values.get_int_value(NonLocalizable::OverlappingZonesAlgorithmID))
|
if (auto val = values.get_int_value(NonLocalizable::OverlappingZonesAlgorithmID))
|
||||||
{
|
{
|
||||||
// Avoid undefined behavior
|
// Avoid undefined behavior
|
||||||
if (*val >= 0 || *val < static_cast<int>(OverlappingZonesAlgorithm::EnumElements))
|
if (*val >= 0 && *val < static_cast<int>(OverlappingZonesAlgorithm::EnumElements))
|
||||||
{
|
{
|
||||||
auto algorithm = (OverlappingZonesAlgorithm)*val;
|
auto algorithm = (OverlappingZonesAlgorithm)*val;
|
||||||
if (m_settings.overlappingZonesAlgorithm != algorithm)
|
if (m_settings.overlappingZonesAlgorithm != algorithm)
|
||||||
|
|||||||
@@ -306,26 +306,23 @@ void FancyZonesWindowUtils::SizeWindowToRect(HWND window, RECT rect) noexcept
|
|||||||
::GetWindowPlacement(window, &placement);
|
::GetWindowPlacement(window, &placement);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsWindowVisible(window))
|
if (IsWindowVisible(window))
|
||||||
{
|
|
||||||
placement.showCmd = SW_HIDE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Do not restore minimized windows. We change their placement though so they restore to the correct zone.
|
// Do not restore minimized windows. We change their placement though so they restore to the correct zone.
|
||||||
if ((placement.showCmd != SW_SHOWMINIMIZED) &&
|
if ((placement.showCmd != SW_SHOWMINIMIZED) &&
|
||||||
(placement.showCmd != SW_MINIMIZE))
|
(placement.showCmd != SW_MINIMIZE))
|
||||||
{
|
{
|
||||||
placement.showCmd = SW_RESTORE;
|
// Remove maximized show command to make sure window is moved to the correct zone.
|
||||||
}
|
if (placement.showCmd == SW_SHOWMAXIMIZED)
|
||||||
|
placement.flags &= ~WPF_RESTORETOMAXIMIZED;
|
||||||
|
|
||||||
// Remove maximized show command to make sure window is moved to the correct zone.
|
|
||||||
if (placement.showCmd == SW_SHOWMAXIMIZED)
|
|
||||||
{
|
|
||||||
placement.showCmd = SW_RESTORE;
|
placement.showCmd = SW_RESTORE;
|
||||||
placement.flags &= ~WPF_RESTORETOMAXIMIZED;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
placement.showCmd = SW_HIDE;
|
||||||
|
}
|
||||||
|
|
||||||
ScreenToWorkAreaCoords(window, rect);
|
ScreenToWorkAreaCoords(window, rect);
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ namespace KeyboardEventHandlers
|
|||||||
// Num Lock's key state is applied before it is intercepted by low level keyboard hooks, so we have to manually set back the state when we suppress the key. This is done by sending an additional key up, key down set of messages.
|
// Num Lock's key state is applied before it is intercepted by low level keyboard hooks, so we have to manually set back the state when we suppress the key. This is done by sending an additional key up, key down set of messages.
|
||||||
// We need 2 key events because after Num Lock is suppressed, key up to release num lock key and key down to revert the num lock state
|
// We need 2 key events because after Num Lock is suppressed, key up to release num lock key and key down to revert the num lock state
|
||||||
int key_count = 2;
|
int key_count = 2;
|
||||||
LPINPUT keyEventList = new INPUT[size_t(key_count)]();
|
LPINPUT keyEventList = new INPUT[size_t(key_count)]{};
|
||||||
memset(keyEventList, 0, sizeof(keyEventList));
|
|
||||||
|
|
||||||
// Use the suppress flag to ensure these are not intercepted by any remapped keys or shortcuts
|
// Use the suppress flag to ensure these are not intercepted by any remapped keys or shortcuts
|
||||||
Helpers::SetKeyEvent(keyEventList, 0, INPUT_KEYBOARD, VK_NUMLOCK, KEYEVENTF_KEYUP, KeyboardManagerConstants::KEYBOARDMANAGER_SUPPRESS_FLAG);
|
Helpers::SetKeyEvent(keyEventList, 0, INPUT_KEYBOARD, VK_NUMLOCK, KEYEVENTF_KEYUP, KeyboardManagerConstants::KEYBOARDMANAGER_SUPPRESS_FLAG);
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ LRESULT Toolbar::WindowProcessMessages(HWND hwnd, UINT msg, WPARAM wparam, LPARA
|
|||||||
}
|
}
|
||||||
case WM_DPICHANGED:
|
case WM_DPICHANGED:
|
||||||
{
|
{
|
||||||
UINT dpi = LOWORD(dpi);
|
UINT dpi = LOWORD(wparam);
|
||||||
RECT* prcNewWindow = reinterpret_cast<RECT*>(lparam);
|
RECT* prcNewWindow = reinterpret_cast<RECT*>(lparam);
|
||||||
|
|
||||||
POINT suggestedPosition;
|
POINT suggestedPosition;
|
||||||
|
|||||||
@@ -99,8 +99,6 @@ std::string toMediaTypeString(GUID subtype)
|
|||||||
return "MFVideoFormat_D16";
|
return "MFVideoFormat_D16";
|
||||||
else if (subtype == MFVideoFormat_AYUV)
|
else if (subtype == MFVideoFormat_AYUV)
|
||||||
return "MFVideoFormat_AYUV";
|
return "MFVideoFormat_AYUV";
|
||||||
else if (subtype == MFVideoFormat_YUY2)
|
|
||||||
return "MFVideoFormat_YUY2";
|
|
||||||
else if (subtype == MFVideoFormat_YVYU)
|
else if (subtype == MFVideoFormat_YVYU)
|
||||||
return "MFVideoFormat_YVYU";
|
return "MFVideoFormat_YVYU";
|
||||||
else if (subtype == MFVideoFormat_YVU9)
|
else if (subtype == MFVideoFormat_YVU9)
|
||||||
|
|||||||
@@ -616,10 +616,10 @@ void close_settings_window()
|
|||||||
{
|
{
|
||||||
if (g_settings_process_id != 0)
|
if (g_settings_process_id != 0)
|
||||||
{
|
{
|
||||||
HANDLE proc = OpenProcess(PROCESS_TERMINATE, false, g_settings_process_id);
|
wil::unique_handle proc{ OpenProcess(PROCESS_TERMINATE, false, g_settings_process_id) };
|
||||||
if (proc != INVALID_HANDLE_VALUE)
|
if (proc)
|
||||||
{
|
{
|
||||||
TerminateProcess(proc, 0);
|
TerminateProcess(proc.get(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user