[CPP][Analyzers] turn on warning 4189 (#21522)

* Turn on 4189 and fix code

* changes from PR comments
This commit is contained in:
sosssego 2022-11-14 22:15:58 +00:00 committed by GitHub
parent 0a19f0dfc7
commit f408c34aca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 24 additions and 32 deletions

View File

@ -42,7 +42,7 @@
<ClCompile>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<WarningLevel>Level4</WarningLevel>
<DisableSpecificWarnings>26800;28251;4189;4239;4244;4245;4389;4456;4457;4701;6387;4458;4505;4515;4459;4702;6031;6248;26451;28182;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<DisableSpecificWarnings>26800;28251;4239;4244;4245;4389;4456;4457;4701;6387;4458;4505;4515;4459;4702;6031;6248;26451;28182;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<DisableAnalyzeExternal >true</DisableAnalyzeExternal>
<ExternalWarningLevel>TurnOffAllWarnings</ExternalWarningLevel>
<ConformanceMode>false</ConformanceMode>

View File

@ -30,8 +30,6 @@ KeyboardHook::~KeyboardHook()
void KeyboardHook::Start()
{
hookProc = gcnew HookProcDelegate(this, &KeyboardHook::HookProc);
Process ^ curProcess = Process::GetCurrentProcess();
ProcessModule ^ curModule = curProcess->MainModule;
#if defined(DISABLE_LOWLEVEL_HOOKS_WHEN_DEBUGGED)
const bool hookDisabled = IsDebuggerPresent();
#else

View File

@ -425,7 +425,7 @@ void TwoWayPipeMessageIPC::TwoWayPipeMessageIPCImpl::start_named_pipe_server(HAN
if (token != NULL)
{
int err = change_pipe_security_allow_restricted_token(connect_pipe_handle, token);
change_pipe_security_allow_restricted_token(connect_pipe_handle, token);
}
current_connect_pipe_handle = connect_pipe_handle;
}

View File

@ -20,7 +20,7 @@ namespace notifications
}
const auto now = timeutil::now();
const size_t buf_size = sizeof(now);
if (RegSetValueExW(key, nullptr, 0, REG_QWORD, reinterpret_cast<const BYTE*>(&now), sizeof(now)) != ERROR_SUCCESS)
if (RegSetValueExW(key, nullptr, 0, REG_QWORD, reinterpret_cast<const BYTE*>(&now), buf_size) != ERROR_SUCCESS)
{
RegCloseKey(key);
return false;

View File

@ -405,7 +405,7 @@ void notifications::update_toast_progress_bar(std::wstring_view tag, progress_ba
map.Insert(L"progressTitle", params.progress_title);
NotificationData data(map);
NotificationUpdateResult res = notifier.Update(data, tag, DEFAULT_TOAST_GROUP);
notifier.Update(data, tag, DEFAULT_TOAST_GROUP);
}
void notifications::remove_toasts_by_tag(std::wstring_view tag)

View File

@ -57,7 +57,7 @@ namespace updating
const bool architecture_matched = filename_lower.find(required_architecture) != std::wstring::npos;
const bool filename_matched = filename_lower.find(required_filename_pattern) != std::wstring::npos;
const bool asset_matched = extension_matched && architecture_matched && filename_matched;
if (extension_matched && architecture_matched && filename_matched)
if (asset_matched)
{
return std::make_pair(Uri{ asset.GetNamedString(L"browser_download_url") }, std::move(filename_lower));
}

View File

@ -617,7 +617,7 @@ void D2DOverlayWindow::render(ID2D1DeviceContext5* d2d_dc)
}
d2d_dc->Clear();
int x_offset = 0, y_offset = 0, dimension = 0;
int x_offset = 0, y_offset = 0;
auto current_anim_value = (float)animation.value(Animation::AnimFunctions::LINEAR);
SetLayeredWindowAttributes(hwnd, 0, (int)(255 * current_anim_value), LWA_ALPHA);
double pos_anim_value = 1 - animation.value(Animation::AnimFunctions::EASE_OUT_EXPO);

View File

@ -254,7 +254,6 @@ bool FancyZonesWindowUtils::IsProcessOfWindowElevated(HWND window)
pid) };
wil::unique_handle token;
bool elevated = false;
if (OpenProcessToken(hProcess.get(), TOKEN_QUERY, &token))
{

View File

@ -335,9 +335,8 @@ namespace FancyZonesUnitTests
.monitorId = { .deviceId = { .id = L"DELA026", .instanceId = L"5&10a58c63&0&UID16777488" } },
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}").value()
};
const auto window = Mocks::WindowCreate(m_hInst);
Assert::IsFalse(AppZoneHistory::instance().RemoveAppLastZone(nullptr, workAreaId, zoneSetId));
}
};
}
}

View File

@ -18,7 +18,7 @@ namespace KeyboardEventHandlers
// 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, 1, INPUT_KEYBOARD, VK_NUMLOCK, 0, KeyboardManagerConstants::KEYBOARDMANAGER_SUPPRESS_FLAG);
UINT res = ii.SendVirtualInput((UINT)key_count, keyEventList, sizeof(INPUT));
ii.SendVirtualInput((UINT)key_count, keyEventList, sizeof(INPUT));
delete[] keyEventList;
}
}

View File

@ -20,7 +20,7 @@ HINSTANCE g_hostHInst = HINST_THISCOMPONENT;
namespace PowerRenameManagerTests
{
TEST_CLASS(SimpleTests)
TEST_CLASS (SimpleTests)
{
public:
struct rename_pairs
@ -78,7 +78,6 @@ namespace PowerRenameManagerTests
}
// TODO: Setup match and replace parameters
wchar_t newReplaceTerm[MAX_PATH] = { 0 };
CComPtr<IPowerRenameRegEx> renRegEx;
Assert::IsTrue(mgr->GetRenameRegEx(&renRegEx) == S_OK);
renRegEx->PutFlags(flags);
@ -110,30 +109,30 @@ namespace PowerRenameManagerTests
mockMgrEvents->Release();
}
TEST_METHOD(CreateTest)
TEST_METHOD (CreateTest)
{
CComPtr<IPowerRenameManager> mgr;
Assert::IsTrue(CPowerRenameManager::s_CreateInstance(&mgr) == S_OK);
}
TEST_METHOD(CreateAndShutdownTest)
TEST_METHOD (CreateAndShutdownTest)
{
CComPtr<IPowerRenameManager> mgr;
Assert::IsTrue(CPowerRenameManager::s_CreateInstance(&mgr) == S_OK);
Assert::IsTrue(mgr->Shutdown() == S_OK);
}
TEST_METHOD(AddItemTest)
TEST_METHOD (AddItemTest)
{
CComPtr<IPowerRenameManager> mgr;
Assert::IsTrue(CPowerRenameManager::s_CreateInstance(&mgr) == S_OK);
CComPtr<IPowerRenameItem> item;
CMockPowerRenameItem::CreateInstance(L"foo", L"foo", 0, false, SYSTEMTIME{0}, &item);
CMockPowerRenameItem::CreateInstance(L"foo", L"foo", 0, false, SYSTEMTIME{ 0 }, &item);
mgr->AddItem(item);
Assert::IsTrue(mgr->Shutdown() == S_OK);
}
TEST_METHOD(VerifyRenameManagerEvents)
TEST_METHOD (VerifyRenameManagerEvents)
{
CComPtr<IPowerRenameManager> mgr;
Assert::IsTrue(CPowerRenameManager::s_CreateInstance(&mgr) == S_OK);
@ -143,7 +142,7 @@ namespace PowerRenameManagerTests
DWORD cookie = 0;
Assert::IsTrue(mgr->Advise(mgrEvents, &cookie) == S_OK);
CComPtr<IPowerRenameItem> item;
CMockPowerRenameItem::CreateInstance(L"foo", L"foo", 0, false, SYSTEMTIME{0}, &item);
CMockPowerRenameItem::CreateInstance(L"foo", L"foo", 0, false, SYSTEMTIME{ 0 }, &item);
int itemId = 0;
Assert::IsTrue(item->GetId(&itemId) == S_OK);
mgr->AddItem(item);
@ -158,7 +157,7 @@ namespace PowerRenameManagerTests
mockMgrEvents->Release();
}
TEST_METHOD(VerifySingleRename)
TEST_METHOD (VerifySingleRename)
{
// Create a single item and verify rename works as expected
rename_pairs renamePairs[] = {
@ -168,7 +167,7 @@ namespace PowerRenameManagerTests
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", SYSTEMTIME{ 2020, 7, 3, 22, 15, 6, 42, 453 }, DEFAULT_FLAGS);
}
TEST_METHOD(VerifyMultiRename)
TEST_METHOD (VerifyMultiRename)
{
// Create a single item and verify rename works as expected
rename_pairs renamePairs[] = {
@ -183,7 +182,7 @@ namespace PowerRenameManagerTests
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", SYSTEMTIME{ 2020, 7, 3, 22, 15, 6, 42, 453 }, DEFAULT_FLAGS);
}
TEST_METHOD(VerifyFilesOnlyRename)
TEST_METHOD (VerifyFilesOnlyRename)
{
// Verify only files are renamed when folders match too
rename_pairs renamePairs[] = {
@ -194,7 +193,7 @@ namespace PowerRenameManagerTests
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", SYSTEMTIME{ 2020, 7, 3, 22, 15, 6, 42, 453 }, DEFAULT_FLAGS | ExcludeFolders);
}
TEST_METHOD(VerifyFoldersOnlyRename)
TEST_METHOD (VerifyFoldersOnlyRename)
{
// Verify only folders are renamed when files match too
rename_pairs renamePairs[] = {
@ -205,7 +204,7 @@ namespace PowerRenameManagerTests
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", SYSTEMTIME{ 2020, 7, 3, 22, 15, 6, 42, 453 }, DEFAULT_FLAGS | ExcludeFiles);
}
TEST_METHOD(VerifyFileNameOnlyRename)
TEST_METHOD (VerifyFileNameOnlyRename)
{
// Verify only file name is renamed, not extension
rename_pairs renamePairs[] = {
@ -216,7 +215,7 @@ namespace PowerRenameManagerTests
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", SYSTEMTIME{ 2020, 7, 3, 22, 15, 6, 42, 453 }, DEFAULT_FLAGS | NameOnly);
}
TEST_METHOD(VerifyFileExtensionOnlyRename)
TEST_METHOD (VerifyFileExtensionOnlyRename)
{
// Verify only file extension is renamed, not name
rename_pairs renamePairs[] = {
@ -227,7 +226,7 @@ namespace PowerRenameManagerTests
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", SYSTEMTIME{ 2020, 7, 3, 22, 15, 6, 42, 453 }, DEFAULT_FLAGS | ExtensionOnly);
}
TEST_METHOD(VerifySubFoldersRename)
TEST_METHOD (VerifySubFoldersRename)
{
// Verify subfolders do not get renamed
rename_pairs renamePairs[] = {
@ -301,7 +300,6 @@ namespace PowerRenameManagerTests
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", SYSTEMTIME{ 2020, 7, 3, 22, 15, 6, 42, 453 }, DEFAULT_FLAGS | Lowercase | ExtensionOnly);
}
TEST_METHOD (VerifyFileAttributesNoPadding)
{
rename_pairs renamePairs[] = {

View File

@ -460,7 +460,6 @@ int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR l
// Apply the general settings but don't save it as the modules() variable has not been loaded yet
apply_general_settings(general_settings, false);
int rvalue = 0;
const bool elevated = is_process_elevated();
const bool with_dont_elevate_arg = cmdLine.find("--dont-elevate") != std::string::npos;
const bool run_elevated_setting = general_settings.GetNamedBoolean(L"run_elevated", false);

View File

@ -62,7 +62,6 @@ optional<path> GetRootPath()
wstring GetChecksum(path filePath)
{
DWORD dwStatus = 0;
BOOL bResult = FALSE;
HCRYPTPROV hProv = 0;
HCRYPTHASH hHash = 0;

View File

@ -57,7 +57,7 @@ namespace
vector<pair<wstring, wstring>> QueryValues(HKEY key)
{
DWORD cValues;
DWORD retCode = RegQueryInfoKeyW(key, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &cValues, nullptr, nullptr, nullptr, nullptr);
RegQueryInfoKeyW(key, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &cValues, nullptr, nullptr, nullptr, nullptr);
TCHAR achValue[255];
DWORD cchValue = 255;
LPBYTE value;
@ -282,7 +282,7 @@ void ReportRegistry(const filesystem::path& tmpDir)
{
DWORD data = 0;
DWORD dataSize = sizeof(data);
LONG retCode = RegGetValueW(rootKey, subKey.c_str(), value.c_str(), flags, &type, &data, &dataSize);
result = RegGetValueW(rootKey, subKey.c_str(), value.c_str(), flags, &type, &data, &dataSize);
if (result == ERROR_SUCCESS)
{
registryReport << "\t" << value << " > " << data << "\n";