From c103875cd9fb8f3e2db9d40688c5afd51c072cd8 Mon Sep 17 00:00:00 2001 From: dantmnf Date: Mon, 5 Sep 2022 01:54:44 +0800 Subject: [PATCH] fix: add variable initialization --- src/MeoAssistant/AsstPlatformWin32.cpp | 6 +++--- src/MeoAssistant/Controller.cpp | 10 +++++----- src/MeoAssistant/OcrPack.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/MeoAssistant/AsstPlatformWin32.cpp b/src/MeoAssistant/AsstPlatformWin32.cpp index 8cd4f81979..0eb4a8624d 100644 --- a/src/MeoAssistant/AsstPlatformWin32.cpp +++ b/src/MeoAssistant/AsstPlatformWin32.cpp @@ -38,7 +38,7 @@ std::string asst::utils::path_to_crt_string(const std::filesystem::path& path) { // UCRT may use UTF-8 encoding while ANSI code page is still some other MBCS encoding // so we use CRT wcstombs instead of WideCharToMultiByte - size_t mbsize; + size_t mbsize = 0; auto osstr = path.native(); auto err = wcstombs_s(&mbsize, nullptr, 0, osstr.c_str(), osstr.size()); if (err == 0) { @@ -108,8 +108,8 @@ std::string asst::utils::callcmd(const std::string& cmdline) auto pipe_buffer = std::make_unique(PipeBuffSize); std::string pipe_str; - DWORD err; - HANDLE pipe_parent_read, pipe_child_write; + DWORD err = 0; + HANDLE pipe_parent_read = INVALID_HANDLE_VALUE, pipe_child_write = INVALID_HANDLE_VALUE; SECURITY_ATTRIBUTES sa_inherit { .nLength = sizeof(SECURITY_ATTRIBUTES), .bInheritHandle = TRUE }; if (!asst::win32::CreateOverlappablePipe(&pipe_parent_read, &pipe_child_write, nullptr, &sa_inherit, PipeBuffSize, true, false)) { diff --git a/src/MeoAssistant/Controller.cpp b/src/MeoAssistant/Controller.cpp index e5d1cc973f..1d579a944d 100644 --- a/src/MeoAssistant/Controller.cpp +++ b/src/MeoAssistant/Controller.cpp @@ -202,15 +202,15 @@ std::optional asst::Controller::call_command(const std::string& cmd using namespace std::chrono; // LogTraceScope(std::string(__FUNCTION__) + " | `" + cmd + "`"); - std::vector pipe_data; - std::vector sock_data; + std::string pipe_data; + std::string sock_data; auto start_time = steady_clock::now(); #ifdef _WIN32 - DWORD err; - HANDLE pipe_parent_read, pipe_child_write; + DWORD err = 0; + HANDLE pipe_parent_read = INVALID_HANDLE_VALUE, pipe_child_write = INVALID_HANDLE_VALUE; SECURITY_ATTRIBUTES sa_inherit { .nLength = sizeof(SECURITY_ATTRIBUTES), .bInheritHandle = TRUE }; if (!asst::win32::CreateOverlappablePipe(&pipe_parent_read, &pipe_child_write, nullptr, &sa_inherit, PipeBuffSize, true, false)) { @@ -1200,7 +1200,7 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a } } - auto socket_opt = try_to_init_socket(bind_address, adb_cfg.nc_port); + auto socket_opt = try_to_init_socket(bind_address); if (socket_opt) { nc_port = socket_opt.value(); m_adb.screencap_raw_by_nc = cmd_replace(adb_cfg.screencap_raw_by_nc); diff --git a/src/MeoAssistant/OcrPack.cpp b/src/MeoAssistant/OcrPack.cpp index 2f4072f097..f1dfbac314 100644 --- a/src/MeoAssistant/OcrPack.cpp +++ b/src/MeoAssistant/OcrPack.cpp @@ -42,7 +42,7 @@ asst::OcrPack::~OcrPack() bool asst::OcrPack::load(const std::filesystem::path& path) { - bool use_temp_dir; + bool use_temp_dir = false; auto paddle_dir = prepare_paddle_dir(path, &use_temp_dir); if (paddle_dir.empty() || !std::filesystem::exists(paddle_dir)) { @@ -63,9 +63,9 @@ bool asst::OcrPack::load(const std::filesystem::path& path) PaddleOcrDestroy(m_ocr); } - const auto det4paddle = asst::utils::path_to_crt_string(dst_filename); - const auto rec4paddle = asst::utils::path_to_crt_string(rec_filename); - const auto keys4paddle = asst::utils::path_to_crt_string(keys_filename); + const auto det4paddle = asst::utils::path_to_ansi_string(dst_filename); + const auto rec4paddle = asst::utils::path_to_ansi_string(rec_filename); + const auto keys4paddle = asst::utils::path_to_ansi_string(keys_filename); if (det4paddle.empty() || rec4paddle.empty() || keys4paddle.empty()) { return false;