From dec47edf0e5ef1c0fa285a48306e3b95bf7859cb Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 01:13:48 +0300 Subject: [PATCH 01/20] client: Do not dereference NULL pointer --- client/cs_notice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cs_notice.cpp b/client/cs_notice.cpp index d57bd40c9d..3696c54813 100644 --- a/client/cs_notice.cpp +++ b/client/cs_notice.cpp @@ -811,7 +811,7 @@ void RSS_FEED_OP::handle_reply(int http_op_retval) { if (!rfp) { if (log_flags.notice_debug) { msg_printf(0, MSG_INFO, - "[notice] RSS feed %s not found", rfp->url + "[notice] RSS feed %s not found", gui_http->http_op.m_url ); } return; From 34f2d0e287ec925636d30f28f4aca6f2281fc968 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 01:20:09 +0300 Subject: [PATCH 02/20] client: Check cuDeviceGetName succeeded --- client/gpu_nvidia.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/gpu_nvidia.cpp b/client/gpu_nvidia.cpp index 5d6ddc2a01..8e91438d5c 100644 --- a/client/gpu_nvidia.cpp +++ b/client/gpu_nvidia.cpp @@ -400,7 +400,7 @@ void* cudalib = NULL; warnings.push_back(buf); goto leave; } - (*p_cuDeviceGetName)(cc.prop.name, 256, device); + retval = (*p_cuDeviceGetName)(cc.prop.name, 256, device); if (retval) { sprintf(buf, "cuDeviceGetName(%d) returned %d", j, retval); warnings.push_back(buf); From ec85870510698c675131b6ca8e8c0246ea820954 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 01:23:22 +0300 Subject: [PATCH 03/20] client: Remove already false condition --- client/cs_notice.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/client/cs_notice.cpp b/client/cs_notice.cpp index 3696c54813..79d26cc6eb 100644 --- a/client/cs_notice.cpp +++ b/client/cs_notice.cpp @@ -512,7 +512,6 @@ void NOTICES::write_archive(RSS_FEED* rfp) { MIOFILE fout; fout.init_file(f); fout.printf("\n"); - if (!f) return; for (unsigned int i=0; i Date: Thu, 7 May 2020 01:26:33 +0300 Subject: [PATCH 04/20] client: Remove already true condition --- client/hostinfo_win.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client/hostinfo_win.cpp b/client/hostinfo_win.cpp index 2aa6873fb4..d1554734c5 100644 --- a/client/hostinfo_win.cpp +++ b/client/hostinfo_win.cpp @@ -1362,10 +1362,8 @@ int get_network_usage_totals(unsigned int& total_received, unsigned int& total_s } } - if (pIfTable != NULL) { - free(pIfTable); - pIfTable = NULL; - } + free(pIfTable); + pIfTable = NULL; return iRetVal; } From 07729834ba9147c1540cfbeb7e102455f4961f36 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 01:30:32 +0300 Subject: [PATCH 05/20] lib: Use MSVC warning override scope pragma warning(default: X) sets the 'X' warning to the DEFAULT state. Correct way is disable warning for scope and restore it to state BEFORE the scope when it ends. See https://www.viva64.com/en/w/v665/print/ --- lib/msg_log.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/msg_log.h b/lib/msg_log.h index 191c374e32..c07e2f7439 100644 --- a/lib/msg_log.h +++ b/lib/msg_log.h @@ -75,6 +75,7 @@ protected: // See lib/msg_log.C for commentary // #if _MSC_VER >= 1300 +#pragma warning(push) #pragma warning(disable: 4512) // assignment operator could not be generated #endif @@ -94,7 +95,7 @@ public: }; #if _MSC_VER >= 1300 -#pragma warning(default: 4512) // assignment operator could not be generated +#pragma warning(pop) #endif #ifdef _USING_FCGI_ From 3ee78d64ec55c3efffbbce7884a789579faabb1b Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:07:12 +0300 Subject: [PATCH 06/20] client: Fix printf format specifiers --- client/app_control.cpp | 2 +- client/gpu_amd.cpp | 2 +- client/gpu_opencl.cpp | 14 +++++++------- client/http_curl.cpp | 2 +- client/sysmon_win.cpp | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client/app_control.cpp b/client/app_control.cpp index d85053885c..e6e343e9ad 100644 --- a/client/app_control.cpp +++ b/client/app_control.cpp @@ -502,7 +502,7 @@ void ACTIVE_TASK::handle_exited_app(int stat) { char szError[1024]; set_task_state(PROCESS_EXITED, "handle_exited_app"); snprintf(err_msg, sizeof(err_msg), - "%s - exit code %d (0x%x)", + "%s - exit code %lu (0x%x)", windows_format_error_string(exit_code, szError, sizeof(szError)), exit_code, exit_code ); diff --git a/client/gpu_amd.cpp b/client/gpu_amd.cpp index 9c0c2abffd..d5eba3446e 100644 --- a/client/gpu_amd.cpp +++ b/client/gpu_amd.cpp @@ -372,7 +372,7 @@ void COPROC_ATI::get( cc.attribs = attribs; cc.info = info; safe_strcpy(cc.name, gpu_name.c_str()); - snprintf(cc.version, sizeof(cc.version), "%d.%d.%d", cal_major, cal_minor, cal_imp); + snprintf(cc.version, sizeof(cc.version), "%u.%u.%u", cal_major, cal_minor, cal_imp); cc.amdrt_detected = amdrt_detected; cc.atirt_detected = atirt_detected; cc.device_num = i; diff --git a/client/gpu_opencl.cpp b/client/gpu_opencl.cpp index 5d9c668c26..1f3f49938f 100644 --- a/client/gpu_opencl.cpp +++ b/client/gpu_opencl.cpp @@ -282,7 +282,7 @@ void COPROCS::get_opencl( ); if (ciErrNum != CL_SUCCESS) { snprintf(buf, sizeof(buf), - "Couldn't get PLATFORM_VERSION for platform #%d; error %d", + "Couldn't get PLATFORM_VERSION for platform #%u; error %d", platform_index, ciErrNum ); warnings.push_back(buf); @@ -295,7 +295,7 @@ void COPROCS::get_opencl( ); if (ciErrNum != CL_SUCCESS) { snprintf(buf, sizeof(buf), - "Couldn't get PLATFORM_VENDOR for platform #%d; error %d", + "Couldn't get PLATFORM_VENDOR for platform #%u; error %d", platform_index, ciErrNum ); warnings.push_back(buf); @@ -312,7 +312,7 @@ void COPROCS::get_opencl( num_devices = 0; // No devices if (ciErrNum != CL_DEVICE_NOT_FOUND) { snprintf(buf, sizeof(buf), - "Couldn't get CPU Device IDs for platform #%d: error %d", + "Couldn't get CPU Device IDs for platform #%u: error %d", platform_index, ciErrNum ); warnings.push_back(buf); @@ -352,7 +352,7 @@ void COPROCS::get_opencl( if (ciErrNum != CL_SUCCESS) { snprintf(buf, sizeof(buf), - "Couldn't get Device IDs for platform #%d: error %d", + "Couldn't get Device IDs for platform #%u: error %d", platform_index, ciErrNum ); warnings.push_back(buf); @@ -449,7 +449,7 @@ void COPROCS::get_opencl( while (1) { if (current_CUDA_index >= (int)(nvidia_gpus.size())) { snprintf(buf, sizeof(buf), - "OpenCL NVIDIA index #%d does not match any CUDA device", + "OpenCL NVIDIA index #%u does not match any CUDA device", device_index ); warnings.push_back(buf); @@ -522,7 +522,7 @@ void COPROCS::get_opencl( while (1) { if (current_CAL_index >= num_CAL_devices) { snprintf(buf, sizeof(buf), - "OpenCL ATI device #%d does not match any CAL device", + "OpenCL ATI device #%u does not match any CAL device", device_index ); warnings.push_back(buf); @@ -626,7 +626,7 @@ void COPROCS::get_opencl( if (prop.peak_flops <= 0 || prop.peak_flops > GPU_MAX_PEAK_FLOPS) { char buf2[256]; sprintf(buf2, - "OpenCL generic: bad peak FLOPS; Max units %d, max freq %d MHz", + "OpenCL generic: bad peak FLOPS; Max units %u, max freq %u MHz", prop.max_compute_units, prop.max_clock_frequency ); warnings.push_back(buf2); diff --git a/client/http_curl.cpp b/client/http_curl.cpp index 9a9b4c37e1..96407f3991 100644 --- a/client/http_curl.cpp +++ b/client/http_curl.cpp @@ -191,7 +191,7 @@ void libcurl_logdebug( char hdr[256]; char buf[2048], *p = buf; - sprintf(hdr, "[ID#%d] %s", phop->trace_id, desc); + sprintf(hdr, "[ID#%u] %s", phop->trace_id, desc); strlcpy(buf, data, sizeof(buf)); diff --git a/client/sysmon_win.cpp b/client/sysmon_win.cpp index 2ce578af8c..c529a8e507 100644 --- a/client/sysmon_win.cpp +++ b/client/sysmon_win.cpp @@ -703,7 +703,7 @@ VOID LogEventErrorMessage(LPTSTR lpszMsg) { // hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME)); - _stprintf_s(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), dwErr); + _stprintf_s(szMsg, TEXT("%s error: %lu"), TEXT(SZSERVICENAME), dwErr); lpszStrings[0] = szMsg; lpszStrings[1] = lpszMsg; From 0310960571248a8df4604c6b890a135d8e551286 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:09:52 +0300 Subject: [PATCH 07/20] client: Use explicit battery state code with same value (0) --- client/hostinfo_win.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/hostinfo_win.cpp b/client/hostinfo_win.cpp index d1554734c5..d1369781ed 100644 --- a/client/hostinfo_win.cpp +++ b/client/hostinfo_win.cpp @@ -1544,7 +1544,7 @@ int HOST_INFO::get_host_battery_state() { SYSTEM_POWER_STATUS Status; ZeroMemory(&Status, sizeof(SYSTEM_POWER_STATUS)); if (!GetSystemPowerStatus(&Status)) { - return false; + return BATTERY_STATE_UNKNOWN; } // Sometimes the system reports the ACLineStatus as an From 471114fd5a7be89611213274812b5f73497722d1 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:12:48 +0300 Subject: [PATCH 08/20] client: If CreateProcess succeeds, the return value is nonzero It is not correct to compare CreateProcess result with TRUE value. Docs say for success return value is nonzero, not only TRUE. --- client/hostinfo_wsl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/hostinfo_wsl.cpp b/client/hostinfo_wsl.cpp index bc3abeb8f1..b7790344b2 100644 --- a/client/hostinfo_wsl.cpp +++ b/client/hostinfo_wsl.cpp @@ -138,7 +138,7 @@ bool CreateWslProcess(const std::string& wsl_app, const std::string& command, HA const std::string cmd = wsl_app + " " + command; - const bool res = (CreateProcess(NULL, (LPSTR)cmd.c_str(), NULL, NULL, TRUE, dwFlags, NULL, NULL, &si, &pi) == TRUE); + const bool res = (CreateProcess(NULL, (LPSTR)cmd.c_str(), NULL, NULL, TRUE, dwFlags, NULL, NULL, &si, &pi) != FALSE); if (res) { handle = pi.hProcess; From fc3395ee463f2fce0f71bdb1e1cf01239f8b4a3f Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:17:22 +0300 Subject: [PATCH 09/20] lib: Make macro safe to use (operations priority) --- lib/crypt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/crypt.h b/lib/crypt.h index 63c577a36a..40a80c2d09 100644 --- a/lib/crypt.h +++ b/lib/crypt.h @@ -72,7 +72,7 @@ struct DATA_BLOCK { unsigned int len; }; -#define MIN_OUT_BUFFER_SIZE MAX_RSA_MODULUS_LEN+1 +#define MIN_OUT_BUFFER_SIZE (MAX_RSA_MODULUS_LEN+1) // the size of a binary signature (encrypted MD5) // From 62723550f6dae8bca6b77cc6466eb7b834fe9ae6 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:18:10 +0300 Subject: [PATCH 10/20] client: Make macro safe to use (operations priority) --- client/async_file.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/async_file.cpp b/client/async_file.cpp index e0fa9039ad..3b30541929 100644 --- a/client/async_file.cpp +++ b/client/async_file.cpp @@ -50,7 +50,7 @@ using std::vector; vector async_verifies; vector async_copies; -#define BUFSIZE 64*1024 +#define BUFSIZE (64*1024) // set up an async copy operation. // From 0cbadc8b312e64f7fea6f35b15dab24464122446 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:19:24 +0300 Subject: [PATCH 11/20] client: Remove setting of the same values again --- client/sysmon_win.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/client/sysmon_win.cpp b/client/sysmon_win.cpp index c529a8e507..8ffe58e9eb 100644 --- a/client/sysmon_win.cpp +++ b/client/sysmon_win.cpp @@ -438,7 +438,6 @@ int initialize_system_monitor(int /*argc*/, char** /*argv*/) { ); if (!g_hWindowsMonitorSystemPowerThread) { - g_hWindowsMonitorSystemPowerThread = NULL; g_hWndWindowsMonitorSystemPower = NULL; } @@ -453,10 +452,6 @@ int initialize_system_monitor(int /*argc*/, char** /*argv*/) { 0, NULL ); - - if (!g_hWindowsMonitorSystemProxyThread) { - g_hWindowsMonitorSystemProxyThread = NULL; - } } return 0; From 65deb853d378c83702e647038e77b671eae85439 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:21:07 +0300 Subject: [PATCH 12/20] client: Remove string -> char* -> string cast --- client/sysmon_win.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/sysmon_win.cpp b/client/sysmon_win.cpp index 8ffe58e9eb..5131db6ffd 100644 --- a/client/sysmon_win.cpp +++ b/client/sysmon_win.cpp @@ -301,7 +301,7 @@ static void windows_detect_autoproxy_settings() { WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A; autoproxy_options.fAutoLogonIfChallenged = TRUE; - network_test_url = boinc_ascii_to_wide(nvc_config.network_test_url).c_str(); + network_test_url = boinc_ascii_to_wide(nvc_config.network_test_url); hWinHttp = WinHttpOpen( L"BOINC client", From d9b7a812837d66fad569c6379ab82153eae34869 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:24:56 +0300 Subject: [PATCH 13/20] client: It is more efficient to seek 'X' character rather than a string --- client/acct_mgr.cpp | 2 +- client/app_start.cpp | 2 +- client/client_types.cpp | 4 ++-- client/file_names.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/acct_mgr.cpp b/client/acct_mgr.cpp index 113f7c6632..4a05f2b727 100644 --- a/client/acct_mgr.cpp +++ b/client/acct_mgr.cpp @@ -501,7 +501,7 @@ int ACCT_MGR_OP::parse(FILE* f) { } static inline bool is_weak_auth(const char* auth) { - return (strstr(auth, "_") != NULL); + return (strchr(auth, '_') != NULL); } #ifdef SIM diff --git a/client/app_start.cpp b/client/app_start.cpp index c5f567afa4..c0933623ce 100644 --- a/client/app_start.cpp +++ b/client/app_start.cpp @@ -337,7 +337,7 @@ static int create_dirs_for_logical_name( safe_strcpy(dir_path, slot_dir); char* p = buf; while (1) { - char* q = strstr(p, "/"); + char* q = strchr(p, '/'); if (!q) break; *q = 0; safe_strcat(dir_path, "/"); diff --git a/client/client_types.cpp b/client/client_types.cpp index 1388c9a6ce..ca9b5c5c33 100644 --- a/client/client_types.cpp +++ b/client/client_types.cpp @@ -304,7 +304,7 @@ int FILE_INFO::parse(XML_PARSER& xp) { if (xp.match_tag("/file_info") || xp.match_tag("/file")) { if (!strlen(name)) return ERR_BAD_FILENAME; if (strstr(name, "..")) return ERR_BAD_FILENAME; - if (strstr(name, "%")) return ERR_BAD_FILENAME; + if (strchr(name, '%')) return ERR_BAD_FILENAME; if (gzipped_urls.size() > 0) { download_urls.clear(); download_urls.urls = gzipped_urls; @@ -1054,7 +1054,7 @@ int FILE_REF::parse(XML_PARSER& xp) { while (!xp.get_tag()) { if (xp.match_tag("/file_ref")) { if (strstr(open_name, "..")) return ERR_BAD_FILENAME; - if (strstr(open_name, "%")) return ERR_BAD_FILENAME; + if (strchr(open_name, '%')) return ERR_BAD_FILENAME; return 0; } if (xp.parse_str("file_name", file_name, sizeof(file_name))) continue; diff --git a/client/file_names.cpp b/client/file_names.cpp index ca86e29ef8..2a5542186d 100644 --- a/client/file_names.cpp +++ b/client/file_names.cpp @@ -296,7 +296,7 @@ bool is_statistics_file(const char* filename) { if (p != filename) return false; q = filename + strlen("statistics_"); - p = strstr(q, "."); + p = strchr(q, '.'); if (!p) return false; if (p == q) return false; From 40d366dedd39e51d2700f32a73213176afbc3a44 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:29:46 +0300 Subject: [PATCH 14/20] client: Cache app access to up performance --- client/cs_scheduler.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/client/cs_scheduler.cpp b/client/cs_scheduler.cpp index 40bca586e0..50ab9de798 100644 --- a/client/cs_scheduler.cpp +++ b/client/cs_scheduler.cpp @@ -801,16 +801,17 @@ int CLIENT_STATE::handle_scheduler_reply( // copy new entities to client state // for (i=0; iuser_friendly_name, sr.apps[i].user_friendly_name); - app->non_cpu_intensive = sr.apps[i].non_cpu_intensive; - app->fraction_done_exact = sr.apps[i].fraction_done_exact; + safe_strcpy(app->user_friendly_name, checked_app.user_friendly_name); + app->non_cpu_intensive = checked_app.non_cpu_intensive; + app->fraction_done_exact = checked_app.fraction_done_exact; } else { app = new APP; - *app = sr.apps[i]; + *app = checked_app; retval = link_app(project, app); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, From 5a9994ffc197bb2901d74d332ca88d3c780b9810 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:31:58 +0300 Subject: [PATCH 15/20] client: Remove excessive vector copying --- client/app_control.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/app_control.cpp b/client/app_control.cpp index e6e343e9ad..750e53de66 100644 --- a/client/app_control.cpp +++ b/client/app_control.cpp @@ -190,7 +190,7 @@ bool ACTIVE_TASK::kill_all_children() { #endif #endif -static void print_descendants(int pid, vectordesc, const char* where) { +static void print_descendants(int pid, const vector& desc, const char* where) { msg_printf(0, MSG_INFO, "%s: PID %d has %d descendants", where, pid, (int)desc.size() ); From 133974d63fcede2fffd970323fd0480b3a2789a7 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:34:25 +0300 Subject: [PATCH 16/20] client: Remove excessive copying of NOTICE class --- client/cs_notice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/cs_notice.cpp b/client/cs_notice.cpp index 79d26cc6eb..280d341582 100644 --- a/client/cs_notice.cpp +++ b/client/cs_notice.cpp @@ -50,7 +50,7 @@ RSS_FEED_OP rss_feed_op; ////////////// UTILITY FUNCTIONS /////////////// -static bool cmp(NOTICE n1, NOTICE n2) { +static bool cmp(const NOTICE& n1, const NOTICE& n2) { if (n1.arrival_time > n2.arrival_time) return true; if (n1.arrival_time < n2.arrival_time) return false; return (strcmp(n1.guid, n2.guid) > 0); @@ -683,7 +683,7 @@ void RSS_FEED::write(MIOFILE& fout) { ); } -static inline bool create_time_asc(NOTICE n1, NOTICE n2) { +static inline bool create_time_asc(const NOTICE& n1, const NOTICE& n2) { return n1.create_time < n2.create_time; } From 4294f50a296a4188481067c8c316e574ec8e27d4 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:38:02 +0300 Subject: [PATCH 17/20] client: It is more efficient to use an initialization list rather than an assignment operator See https://www.viva64.com/en/w/v818/print/ --- client/cs_trickle.h | 3 +-- client/scheduler_op.cpp | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/client/cs_trickle.h b/client/cs_trickle.h index f926cfc649..b061176926 100644 --- a/client/cs_trickle.h +++ b/client/cs_trickle.h @@ -28,8 +28,7 @@ struct TRICKLE_UP_OP: public GUI_HTTP_OP { int error_num; char* req_buf; - TRICKLE_UP_OP(std::string& u) { - url = u; + TRICKLE_UP_OP(std::string& u) : url(u) { error_num = 0; gui_http = new GUI_HTTP; req_buf = NULL; diff --git a/client/scheduler_op.cpp b/client/scheduler_op.cpp index f8db720ad8..d6a10ff34b 100644 --- a/client/scheduler_op.cpp +++ b/client/scheduler_op.cpp @@ -937,8 +937,6 @@ int SCHEDULER_REPLY::parse(FILE* in, PROJECT* project) { } #endif -USER_MESSAGE::USER_MESSAGE(char* m, char* p) { - message = m; - priority = p; +USER_MESSAGE::USER_MESSAGE(char* m, char* p) : message(m), priority(p) { } From c09041eb7a3852d3e23c37915bc9d6c9c6a42cef Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:43:14 +0300 Subject: [PATCH 18/20] client: Use string.clear() instead of = '' to increase performance --- client/acct_mgr.cpp | 10 +++++----- client/acct_mgr.h | 2 +- client/acct_setup.cpp | 12 ++++++------ client/client_types.cpp | 4 ++-- client/client_types.h | 2 +- client/current_version.cpp | 2 +- client/hostinfo_wsl.cpp | 6 +++--- client/project.cpp | 4 ++-- client/result.cpp | 4 ++-- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/client/acct_mgr.cpp b/client/acct_mgr.cpp index 4a05f2b727..50ba9cbe09 100644 --- a/client/acct_mgr.cpp +++ b/client/acct_mgr.cpp @@ -61,9 +61,9 @@ int ACCT_MGR_OP::do_rpc(ACCT_MGR_INFO& _ami, bool _via_gui) { ami = _ami; error_num = ERR_IN_PROGRESS; - error_str = ""; + error_str.clear(); via_gui = _via_gui; - global_prefs_xml = ""; + global_prefs_xml.clear(); // if null URL, detach from current AMS // @@ -298,9 +298,9 @@ int AM_ACCOUNT::parse(XML_PARSER& xp) { detach_when_done.init(); suspend.init(); abort_not_started.init(); - url = ""; + url.clear(); safe_strcpy(url_signature, ""); - authenticator = ""; + authenticator.clear(); resource_share.init(); while (!xp.get_tag()) { @@ -392,7 +392,7 @@ int ACCT_MGR_OP::parse(FILE* f) { XML_PARSER xp(&mf); accounts.clear(); - error_str = ""; + error_str.clear(); error_num = 0; repeat_sec = 0; safe_strcpy(host_venue, ""); diff --git a/client/acct_mgr.h b/client/acct_mgr.h index 4d6ce022e8..cecc250252 100644 --- a/client/acct_mgr.h +++ b/client/acct_mgr.h @@ -194,7 +194,7 @@ struct ACCT_MGR_OP: public GUI_HTTP_OP { via_gui = false; error_num = BOINC_SUCCESS; repeat_sec = 60.0; - global_prefs_xml = ""; + global_prefs_xml.clear(); safe_strcpy(host_venue, ""); got_rss_feeds = false; } diff --git a/client/acct_setup.cpp b/client/acct_setup.cpp index 892f4513ed..defd8f4a46 100644 --- a/client/acct_setup.cpp +++ b/client/acct_setup.cpp @@ -38,12 +38,12 @@ #include "acct_setup.h" void ACCOUNT_IN::parse(XML_PARSER& xp) { - url = ""; - email_addr = ""; - passwd_hash = ""; - user_name = ""; - team_name = ""; - server_cookie = ""; + url.clear(); + email_addr.clear(); + passwd_hash.clear(); + user_name.clear(); + team_name.clear(); + server_cookie.clear(); ldap_auth = false; server_assigned_cookie = false; consented_to_terms = false; diff --git a/client/client_types.cpp b/client/client_types.cpp index ca9b5c5c33..554999f0e1 100644 --- a/client/client_types.cpp +++ b/client/client_types.cpp @@ -228,7 +228,7 @@ FILE_INFO::~FILE_INFO() { void FILE_INFO::reset() { status = FILE_NOT_PRESENT; delete_file(); - error_msg = ""; + error_msg.clear(); } // Set file ownership if using account-based sandbox; @@ -1106,7 +1106,7 @@ int WORKUNIT::parse(XML_PARSER& xp) { safe_strcpy(name, ""); safe_strcpy(app_name, ""); version_num = 0; - command_line = ""; + command_line.clear(); //strcpy(env_vars, ""); app = NULL; project = NULL; diff --git a/client/client_types.h b/client/client_types.h index 0f13b09aae..219ef7f95f 100644 --- a/client/client_types.h +++ b/client/client_types.h @@ -384,7 +384,7 @@ struct WORKUNIT { safe_strcpy(name, ""); safe_strcpy(app_name, ""); version_num = 0; - command_line = ""; + command_line.clear(); input_files.clear(); job_keyword_ids.clear(); project = NULL; diff --git a/client/current_version.cpp b/client/current_version.cpp index aa08d04fb3..08757e3b39 100644 --- a/client/current_version.cpp +++ b/client/current_version.cpp @@ -38,7 +38,7 @@ NVC_CONFIG::NVC_CONFIG() { // void NVC_CONFIG::defaults() { client_download_url = "https://boinc.berkeley.edu/download.php"; - client_new_version_name = ""; + client_new_version_name.clear(); client_version_check_url = DEFAULT_VERSION_CHECK_URL; network_test_url = "https://www.google.com/"; }; diff --git a/client/hostinfo_wsl.cpp b/client/hostinfo_wsl.cpp index b7790344b2..00f2d9d55c 100644 --- a/client/hostinfo_wsl.cpp +++ b/client/hostinfo_wsl.cpp @@ -28,7 +28,7 @@ bool get_available_wsls(std::vector& wsls, std::string& default_wsl HKEY hKey; - default_wsl = ""; + default_wsl.clear(); LONG lRet = RegOpenKeyEx(HKEY_CURRENT_USER, lxss_path.c_str(), @@ -197,8 +197,8 @@ std::string read_from_pipe(HANDLE handle) { void parse_sysctl_output(const std::vector& lines, std::string& ostype, std::string& osrelease) { char buf[256], ostype_found[256], osrelease_found[256]; - ostype = ""; - osrelease = ""; + ostype.clear(); + osrelease.clear(); for (size_t i = 0; i < lines.size(); ++i) { safe_strcpy(buf, lines[i].c_str()); strip_whitespace(buf); diff --git a/client/project.cpp b/client/project.cpp index b349f088e8..0dd770fbdd 100644 --- a/client/project.cpp +++ b/client/project.cpp @@ -44,8 +44,8 @@ void PROJECT::init() { safe_strcpy(authenticator, ""); safe_strcpy(_project_dir, ""); safe_strcpy(_project_dir_absolute, ""); - project_specific_prefs = ""; - gui_urls = ""; + project_specific_prefs.clear(); + gui_urls.clear(); resource_share = 100; resource_share_frac = 0.0; disk_resource_share = 0.0; diff --git a/client/result.cpp b/client/result.cpp index c7c5f8b620..89a5524d89 100644 --- a/client/result.cpp +++ b/client/result.cpp @@ -80,12 +80,12 @@ void RESULT::clear() { intops_cumulative = 0; _state = RESULT_NEW; exit_status = 0; - stderr_out = ""; + stderr_out.clear(); suspended_via_gui = false; coproc_missing = false; report_immediately = false; not_started = false; - name_md5 = ""; + name_md5.clear(); index = 0; app = NULL; wup = NULL; From 65d528f1f8dd2fb2ac63681a44f92a55c2984931 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:44:13 +0300 Subject: [PATCH 19/20] client: Use string.empty() instead of == '' --- client/hostinfo_wsl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/hostinfo_wsl.cpp b/client/hostinfo_wsl.cpp index 00f2d9d55c..6ab80600f0 100644 --- a/client/hostinfo_wsl.cpp +++ b/client/hostinfo_wsl.cpp @@ -89,7 +89,7 @@ bool get_available_wsls(std::vector& wsls, std::string& default_wsl RegCloseKey(hKey); - return default_wsl != ""; + return !default_wsl.empty(); } typedef HRESULT(WINAPI *PWslLaunch)(PCWSTR, PCWSTR, BOOL, HANDLE, HANDLE, HANDLE, HANDLE*); From cefdf875b01c12aa3e1d88583a58d232e96cfe57 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Thu, 7 May 2020 14:54:46 +0300 Subject: [PATCH 20/20] client: Cache frequently used expressions --- client/client_state.cpp | 3 ++- client/cs_scheduler.cpp | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/client/client_state.cpp b/client/client_state.cpp index 09494361a5..b8aed81b8d 100644 --- a/client/client_state.cpp +++ b/client/client_state.cpp @@ -1434,7 +1434,8 @@ void CLIENT_STATE::print_summary() { } msg_printf(0, MSG_INFO, "%d persistent file xfers", (int)pers_file_xfers->pers_file_xfers.size()); for (i=0; ipers_file_xfers.size(); i++) { - msg_printf(0, MSG_INFO, " %s http op state: %d", pers_file_xfers->pers_file_xfers[i]->fip->name, (pers_file_xfers->pers_file_xfers[i]->fxp?pers_file_xfers->pers_file_xfers[i]->fxp->http_op_state:-1)); + const PERS_FILE_XFER* pers_file_xfer = pers_file_xfers->pers_file_xfers[i]; + msg_printf(0, MSG_INFO, " %s http op state: %d", pers_file_xfer->fip->name, pers_file_xfer->fxp?pers_file_xfer->fxp->http_op_state:-1); } msg_printf(0, MSG_INFO, "%d active tasks", (int)active_tasks.active_tasks.size()); for (i=0; ireport_deadline) { - rp2->report_deadline = sr.results[i].report_deadline; + if (checked_result.report_deadline != rp2->report_deadline) { + rp2->report_deadline = checked_result.report_deadline; } else { msg_printf(project, MSG_INTERNAL_ERROR, - "Already have task %s\n", sr.results[i].name + "Already have task %s\n", checked_result.name ); } continue; } RESULT* rp = new RESULT; - *rp = sr.results[i]; + *rp = checked_result; retval = link_result(project, rp); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR,