Skip to content

Commit

Permalink
[Analyzers][CPP]Changes to fix warning 26493 on src/runner (#23672)
Browse files Browse the repository at this point in the history
* Changes to fix warning 26493 on src/runner

* formating
  • Loading branch information
sosssego committed Feb 8, 2023
1 parent 49b2823 commit 9168f87
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/runner/auto_start_helper.cpp
Expand Up @@ -75,7 +75,7 @@ bool create_auto_start_task_for_this_user(bool runElevated)
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService);
reinterpret_cast<void**>(&pService));
ExitOnFailure(hr, "Failed to create an instance of ITaskService: %x", hr);

// Connect to the task service.
Expand Down Expand Up @@ -286,7 +286,7 @@ bool delete_auto_start_task_for_this_user()
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService);
reinterpret_cast<void**>(&pService));
ExitOnFailure(hr, "Failed to create an instance of ITaskService: %x", hr);

// Connect to the task service.
Expand Down Expand Up @@ -351,7 +351,7 @@ bool is_auto_start_task_active_for_this_user()
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService);
reinterpret_cast<void**>(&pService));
ExitOnFailure(hr, "Failed to create an instance of ITaskService: %x", hr);

// Connect to the task service.
Expand Down
10 changes: 5 additions & 5 deletions src/runner/settings_telemetry.cpp
Expand Up @@ -48,7 +48,7 @@ void send()
{
powertoy->send_settings_telemetry();
}
catch(...)
catch (...)
{
Logger::error(L"Failed to send telemetry for {} module", name);
}
Expand All @@ -59,20 +59,20 @@ void send()
void run_interval()
{
auto time = get_last_send_time();
long long wait_time = 24*3600;
long long wait_time = 24 * 3600;
long long left_to_wait = 0;
if (time.has_value())
{
left_to_wait = max(0, wait_time - timeutil::diff::in_seconds(timeutil::now(), time.value()));
}

Sleep((DWORD)left_to_wait * 1000);
Sleep(static_cast<DWORD>(left_to_wait * 1000));
send();
update_last_send_time(timeutil::now());

while (true)
{
Sleep((DWORD)wait_time * 1000);
Sleep(static_cast<DWORD>(wait_time * 1000));
send();
update_last_send_time(timeutil::now());
}
Expand All @@ -87,7 +87,7 @@ void settings_telemetry::init()
}
catch (...)
{
Logger::error("Failed to send settings telemetry");
Logger::error("Failed to send settings telemetry");
}
}).detach();
}
6 changes: 3 additions & 3 deletions src/runner/settings_window.cpp
Expand Up @@ -242,7 +242,7 @@ void dispatch_received_json(const std::wstring& json_to_parse)

void dispatch_received_json_callback(PVOID data)
{
std::wstring* msg = (std::wstring*)data;
std::wstring* msg = static_cast<std::wstring*>(data);
dispatch_received_json(*msg);
delete msg;
}
Expand Down Expand Up @@ -345,7 +345,7 @@ void run_settings_window(bool show_oobe_window, bool show_scoobe_window, std::op
auto val = get_last_error_message(GetLastError());
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());
Logger::warn(L"UuidToString can not convert to string. {}", val.has_value() ? val.value() : L"");
Expand All @@ -355,7 +355,7 @@ void run_settings_window(bool show_oobe_window, bool show_scoobe_window, std::op
{
powertoys_pipe_name += std::wstring(uuid_chars);
settings_pipe_name += std::wstring(uuid_chars);
RpcStringFree((RPC_WSTR*)&uuid_chars);
RpcStringFree(reinterpret_cast<RPC_WSTR*>(&uuid_chars));
uuid_chars = nullptr;
}

Expand Down
7 changes: 3 additions & 4 deletions src/runner/tray_icon.cpp
Expand Up @@ -53,7 +53,7 @@ bool dispatch_run_on_main_ui_thread(main_loop_callback_function _callback, PVOID
wnd_msg->_callback = _callback;
wnd_msg->data = data;

PostMessage(tray_icon_hwnd, wm_run_on_main_ui_thread, 0, (LPARAM)wnd_msg);
PostMessage(tray_icon_hwnd, wm_run_on_main_ui_thread, 0, reinterpret_cast<LPARAM>(wnd_msg));

return true;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ void handle_tray_command(HWND window, const WPARAM command_id, LPARAM lparam)
}
break;
case ID_REPORT_BUG_COMMAND:
{
{
std::wstring bug_report_path = get_module_folderpath();
bug_report_path += L"\\Tools\\PowerToys.BugReportTool.exe";
SHELLEXECUTEINFOW sei{ sizeof(sei) };
Expand All @@ -116,7 +116,6 @@ void handle_tray_command(HWND window, const WPARAM command_id, LPARAM lparam)
RunNonElevatedEx(L"https://aka.ms/PowerToysOverview", L"", L"");
break;
}

}
}

Expand Down Expand Up @@ -242,7 +241,7 @@ LRESULT __stdcall tray_icon_window_proc(HWND window, UINT message, WPARAM wparam
{
if (lparam != NULL)
{
struct run_on_main_ui_thread_msg* msg = (struct run_on_main_ui_thread_msg*)lparam;
struct run_on_main_ui_thread_msg* msg = reinterpret_cast<struct run_on_main_ui_thread_msg*>(lparam);
msg->_callback(msg->data);
delete msg;
lparam = NULL;
Expand Down
20 changes: 10 additions & 10 deletions src/runner/unhandled_exception_handler.cpp
Expand Up @@ -7,7 +7,7 @@
#include <sstream>
#include <csignal>

static IMAGEHLP_SYMBOL64* p_symbol = (IMAGEHLP_SYMBOL64*)malloc(sizeof(IMAGEHLP_SYMBOL64) + MAX_PATH * sizeof(WCHAR));
static IMAGEHLP_SYMBOL64* p_symbol = static_cast<IMAGEHLP_SYMBOL64*>(malloc(sizeof(IMAGEHLP_SYMBOL64) + MAX_PATH * sizeof(WCHAR)));
static IMAGEHLP_LINE64 line;
static bool processing_exception = false;
static WCHAR module_path[MAX_PATH];
Expand Down Expand Up @@ -106,14 +106,14 @@ void log_stack_trace(std::wstring& generalErrorDescription)
#else
IMAGE_FILE_MACHINE_AMD64,
#endif
process,
thread,
&stack,
&context,
NULL,
SymFunctionTableAccess64,
SymGetModuleBase64,
NULL);
process,
thread,
&stack,
&context,
NULL,
SymFunctionTableAccess64,
SymGetModuleBase64,
NULL);

p_symbol->MaxNameLength = MAX_PATH;
p_symbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
Expand All @@ -126,7 +126,7 @@ void log_stack_trace(std::wstring& generalErrorDescription)
auto module_base = SymGetModuleBase64(process, stack.AddrPC.Offset);
if (module_base)
{
GetModuleFileName((HINSTANCE)module_base, module_path, MAX_PATH);
GetModuleFileName(reinterpret_cast<HINSTANCE>(module_base), module_path, MAX_PATH);
}
ss << module_path << "!"
<< p_symbol->Name
Expand Down

0 comments on commit 9168f87

Please sign in to comment.