Merge pull request #3692 from dimhotepus/fixes/pvs_studio_part2

client: PVS Studio static code analyzer fixes
This commit is contained in:
Vitalii Koshura 2020-05-07 15:21:58 +02:00 committed by GitHub
commit 8a75eb80c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 70 additions and 77 deletions

View File

@ -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, "");
@ -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

View File

@ -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;
}

View File

@ -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;

View File

@ -190,7 +190,7 @@ bool ACTIVE_TASK::kill_all_children() {
#endif
#endif
static void print_descendants(int pid, vector<int>desc, const char* where) {
static void print_descendants(int pid, const vector<int>& desc, const char* where) {
msg_printf(0, MSG_INFO, "%s: PID %d has %d descendants",
where, pid, (int)desc.size()
);
@ -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
);

View File

@ -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, "/");

View File

@ -50,7 +50,7 @@ using std::vector;
vector<ASYNC_VERIFY*> async_verifies;
vector<ASYNC_COPY*> async_copies;
#define BUFSIZE 64*1024
#define BUFSIZE (64*1024)
// set up an async copy operation.
//

View File

@ -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; i<pers_file_xfers->pers_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; i<active_tasks.active_tasks.size(); i++) {

View File

@ -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;
@ -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;
@ -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;

View File

@ -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;

View File

@ -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);
@ -512,7 +512,6 @@ void NOTICES::write_archive(RSS_FEED* rfp) {
MIOFILE fout;
fout.init_file(f);
fout.printf("<notices>\n");
if (!f) return;
for (unsigned int i=0; i<notices.size(); i++) {
NOTICE& n = notices[i];
if (rfp) {
@ -684,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;
}
@ -811,7 +810,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;

View File

@ -801,16 +801,17 @@ int CLIENT_STATE::handle_scheduler_reply(
// copy new entities to client state
//
for (i=0; i<sr.apps.size(); i++) {
APP* app = lookup_app(project, sr.apps[i].name);
APP& checked_app = sr.apps[i];
APP* app = lookup_app(project, checked_app.name);
if (app) {
// update app attributes; they may have changed on server
//
safe_strcpy(app->user_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,
@ -939,21 +940,22 @@ int CLIENT_STATE::handle_scheduler_reply(
got_work_for_rsc[j] = false;
}
for (i=0; i<sr.results.size(); i++) {
RESULT* rp2 = lookup_result(project, sr.results[i].name);
RESULT& checked_result = sr.results[i];
RESULT* rp2 = lookup_result(project, checked_result.name);
if (rp2) {
// see if project wants to change the job's deadline
//
if (sr.results[i].report_deadline != rp2->report_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,

View File

@ -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;

View File

@ -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/";
};

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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;
}
@ -1546,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

View File

@ -28,7 +28,7 @@ bool get_available_wsls(std::vector<std::string>& wsls, std::string& default_wsl
HKEY hKey;
default_wsl = "";
default_wsl.clear();
LONG lRet = RegOpenKeyEx(HKEY_CURRENT_USER,
lxss_path.c_str(),
@ -89,7 +89,7 @@ bool get_available_wsls(std::vector<std::string>& 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*);
@ -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;
@ -197,8 +197,8 @@ std::string read_from_pipe(HANDLE handle) {
void parse_sysctl_output(const std::vector<std::string>& 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);

View File

@ -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));

View File

@ -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;

View File

@ -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;

View File

@ -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) {
}

View File

@ -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",
@ -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;
@ -703,7 +698,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;

View File

@ -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)
//

View File

@ -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_