client: Cleanup low hanging fruit with regards to cleaning up sprintf.

Use snprintf instead.
This commit is contained in:
Rom Walton 2016-02-18 00:59:13 -05:00
parent 53b1d04b0f
commit 2cc9a0b6c4
30 changed files with 282 additions and 149 deletions

View File

@ -24,6 +24,10 @@
#include <cstring>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "crypt.h"
#include "error_numbers.h"
#include "parse.h"
@ -201,7 +205,7 @@ int ACCT_MGR_OP::do_rpc(
gstate.net_stats.write(mf);
fprintf(f, "</acct_mgr_request>\n");
fclose(f);
sprintf(buf, "%srpc.php", url);
snprintf(buf, sizeof(buf), "%srpc.php", url);
retval = gui_http->do_rpc_post(
this, buf, ACCT_MGR_REQUEST_FILENAME, ACCT_MGR_REPLY_FILENAME, true
);

View File

@ -52,6 +52,9 @@
#include <cstdlib>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "error_numbers.h"
#include "filesys.h"
@ -517,8 +520,11 @@ int ACTIVE_TASK::move_trickle_file() {
char new_path[MAXPATHLEN], old_path[MAXPATHLEN];
int retval;
sprintf(old_path, "%s/trickle_up.xml", slot_dir);
sprintf(new_path,
snprintf(old_path, sizeof(old_path),
"%s/trickle_up.xml",
slot_dir
);
snprintf(new_path, sizeof(new_path),
"%s/trickle_up_%s_%d.xml",
result->project->project_dir(), result->name, (int)time(0)
);
@ -1060,7 +1066,7 @@ int ACTIVE_TASK::handle_upload_files() {
"Can't find uploadable file %s", p
);
}
sprintf(path, "%s/%s", slot_dir, buf);
snprintf(path, sizeof(path), "%s/%s", slot_dir, buf);
delete_project_owned_file(path, true); // delete the link file
}
}
@ -1095,7 +1101,10 @@ void ACTIVE_TASK_SET::network_available() {
void ACTIVE_TASK::upload_notify_app(const FILE_INFO* fip, const FILE_REF* frp) {
char path[MAXPATHLEN];
sprintf(path, "%s/%s%s", slot_dir, UPLOAD_FILE_STATUS_PREFIX, frp->open_name);
snprintf(path, sizeof(path),
"%s/%s%s",
slot_dir, UPLOAD_FILE_STATUS_PREFIX, frp->open_name
);
FILE* f = boinc_fopen(path, "w");
if (!f) return;
fprintf(f, "<status>%d</status>\n", fip->status);

View File

@ -351,7 +351,7 @@ static int create_dirs_for_logical_name(
static void prepend_prefix(APP_VERSION* avp, char* in, char* out, int len) {
if (strlen(avp->file_prefix)) {
sprintf(out, "%s/%s", avp->file_prefix, in);
snprintf(out, len, "%s/%s", avp->file_prefix, in);
} else {
strlcpy(out, in, len);
}
@ -395,12 +395,12 @@ int ACTIVE_TASK::setup_file(
}
retval = create_dirs_for_logical_name(open_name, slot_dir);
if (retval) return retval;
sprintf(link_path, "%s/%s", slot_dir, open_name);
snprintf(link_path, sizeof(link_path), "%s/%s", slot_dir, open_name);
} else {
sprintf(link_path, "%s/%s", slot_dir, fip->name);
snprintf(link_path, sizeof(link_path), "%s/%s", slot_dir, fip->name);
}
sprintf(rel_file_path, "../../%s", file_path );
snprintf(rel_file_path, sizeof(rel_file_path), "../../%s", file_path );
if (boinc_file_exists(link_path)) {
return 0;
@ -476,7 +476,7 @@ int ACTIVE_TASK::copy_output_files() {
prepend_prefix(
app_version, fref.open_name, open_name, sizeof(open_name)
);
sprintf(slotfile, "%s/%s", slot_dir, open_name);
snprintf(slotfile, sizeof(slotfile), "%s/%s", slot_dir, open_name);
get_pathname(fip, projfile, sizeof(projfile));
int retval = boinc_rename(slotfile, projfile);
// the rename fails if the output file isn't there.
@ -606,7 +606,7 @@ int ACTIVE_TASK::start(bool test) {
if (!app_client_shm.shm) {
retval = get_shmem_seg_name();
if (retval) {
sprintf(buf,
snprintf(buf, sizeof(buf),
"Can't get shared memory segment name: %s",
boincerror(retval)
);
@ -620,7 +620,7 @@ int ACTIVE_TASK::start(bool test) {
init_app_init_data(aid);
retval = write_app_init_file(aid);
if (retval) {
sprintf(buf, "Can't write init file: %s", boincerror(retval));
snprintf(buf, sizeof(buf), "Can't write init file: %s", boincerror(retval));
goto error;
}
@ -638,12 +638,12 @@ int ACTIVE_TASK::start(bool test) {
get_pathname(fip, file_path, sizeof(file_path));
if (fref.main_program) {
if (is_image_file(fip->name)) {
sprintf(buf, "Main program %s is an image file", fip->name);
snprintf(buf, sizeof(buf), "Main program %s is an image file", fip->name);
retval = ERR_NO_SIGNATURE;
goto error;
}
if (!fip->executable && !wup->project->anonymous_platform) {
sprintf(buf, "Main program %s is not executable", fip->name);
snprintf(buf, sizeof(buf), "Main program %s is not executable", fip->name);
retval = ERR_NO_SIGNATURE;
goto error;
}
@ -697,7 +697,7 @@ int ACTIVE_TASK::start(bool test) {
// remove temporary exit file from last run
//
sprintf(file_path, "%s/%s", slot_dir, TEMPORARY_EXIT_FILE);
snprintf(file_path, sizeof(file_path), "%s/%s", slot_dir, TEMPORARY_EXIT_FILE);
delete_project_owned_file(file_path, true);
if (cc_config.exit_before_start) {
@ -732,7 +732,8 @@ int ACTIVE_TASK::start(bool test) {
return 0;
}
sprintf(cmdline, "%s %s %s",
snprintf(cmdline, sizeof(cmdline),
"%s %s %s",
exec_path, wup->command_line.c_str(), app_version->cmdline
);
if (!app_version->api_version_at_least(7, 5)) {
@ -825,7 +826,7 @@ int ACTIVE_TASK::start(bool test) {
}
if (!success) {
sprintf(buf, "CreateProcess() failed - %s", error_msg);
snprintf(buf, sizeof(buf), "CreateProcess() failed - %s", error_msg);
if (last_error == ERROR_NOT_ENOUGH_MEMORY) {
// if CreateProcess() failed because system is low on memory,
@ -884,10 +885,10 @@ int ACTIVE_TASK::start(bool test) {
if (log_flags.task_debug) {
debug_print_argv(argv);
}
sprintf(buf, "../../%s", exec_path );
snprintf(buf, sizeof(buf), "../../%s", exec_path );
pid = spawnv(P_NOWAIT, buf, argv);
if (pid == -1) {
sprintf(buf, "Process creation failed: %s\n", boincerror(retval));
snprintf(buf, sizeof(buf), "Process creation failed: %s\n", boincerror(retval));
chdir(current_dir);
retval = ERR_EXEC;
goto error;
@ -916,11 +917,12 @@ int ACTIVE_TASK::start(bool test) {
char current_dir[1024];
if (getcwd(current_dir, sizeof(current_dir)) == NULL) {
sprintf(buf, "Can't get cwd");
snprintf(buf, sizeof(buf), "Can't get cwd");
goto error;
}
sprintf(cmdline, "%s %s",
snprintf(cmdline, sizeof(cmdline),
"%s %s",
wup->command_line.c_str(), app_version->cmdline
);
@ -940,7 +942,7 @@ int ACTIVE_TASK::start(bool test) {
if (app_version->api_version_at_least(6, 0)) {
#endif
// Use mmap() shared memory
sprintf(buf, "%s/%s", slot_dir, MMAPPED_FILE_NAME);
snprintf(buf, sizeof(buf), "%s/%s", slot_dir, MMAPPED_FILE_NAME);
if (g_use_sandbox) {
if (!boinc_file_exists(buf)) {
int fd = open(buf, O_RDWR | O_CREAT, 0660);
@ -988,7 +990,7 @@ int ACTIVE_TASK::start(bool test) {
}
pid = fork();
if (pid == -1) {
sprintf(buf, "fork() failed: %s", strerror(errno));
snprintf(buf, sizeof(buf), "fork() failed: %s", strerror(errno));
retval = ERR_FORK;
goto error;
}
@ -1013,9 +1015,9 @@ int ACTIVE_TASK::start(bool test) {
//
char libpath[8192];
char newlibs[256];
sprintf(newlibs, "../../%s:.:../..", wup->project->project_dir());
snprintf(newlibs, sizeof(newlibs), "../../%s:.:../..", wup->project->project_dir());
#ifdef __APPLE__
strcat(newlibs, ":/usr/local/cuda/lib/");
strlcat(newlibs, sizeof(newlibs), ":/usr/local/cuda/lib/");
#endif
char* p = getenv("LD_LIBRARY_PATH");
if (p) {
@ -1106,11 +1108,12 @@ int ACTIVE_TASK::start(bool test) {
if (test) {
strcpy(buf, exec_path);
} else {
sprintf(buf, "../../%s", exec_path);
snprintf(buf, sizeof(buf), "../../%s", exec_path);
}
if (g_use_sandbox) {
char switcher_path[MAXPATHLEN];
sprintf(switcher_path, "../../%s/%s",
snprintf(switcher_path, sizeof(switcher_path),
"../../%s/%s",
SWITCHER_DIR, SWITCHER_FILE_NAME
);
argv[0] = const_cast<char*>(SWITCHER_FILE_NAME);
@ -1218,7 +1221,7 @@ int ACTIVE_TASK::resume_or_start(bool first_time) {
char buf[256];
safe_strcpy(buf, "");
if (strlen(app_version->plan_class)) {
sprintf(buf, " (%s)", app_version->plan_class);
snprintf(buf, sizeof(buf), " (%s)", app_version->plan_class);
}
msg_printf(result->project, MSG_INFO,
"[cpu_sched] %s task %s using %s version %d%s in slot %d",

View File

@ -21,6 +21,10 @@
#include <string.h>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "crypt.h"
#include "error_numbers.h"
#include "filesys.h"

View File

@ -36,6 +36,10 @@
#endif
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#ifdef __EMX__
#define INCL_DOS
#include <os2.h>
@ -412,7 +416,7 @@ static void set_client_priority() {
#endif
#ifdef __linux__
char buf[1024];
sprintf(buf, "ionice -c 3 -p %d", getpid());
snprintf(buf, sizeof(buf), "ionice -c 3 -p %d", getpid());
system(buf);
#endif
}
@ -1003,14 +1007,14 @@ bool CLIENT_STATE::poll_slow_events() {
if (!old_network_suspend_reason) {
char buf[256];
if (network_suspended) {
sprintf(buf,
snprintf(buf, sizeof(buf),
"Suspending network activity - %s",
suspend_reason_string(network_suspend_reason)
);
request_schedule_cpus("network suspended");
// in case any "needs_network" jobs are running
} else {
sprintf(buf,
snprintf(buf, sizeof(buf),
"Suspending file transfers - %s",
suspend_reason_string(network_suspend_reason)
);
@ -2080,7 +2084,7 @@ int CLIENT_STATE::detach_project(PROJECT* project) {
// delete statistics file
//
get_statistics_filename(project->master_url, path);
get_statistics_filename(project->master_url, path, sizeof(path));
retval = boinc_delete_file(path);
if (retval) {
msg_printf(project, MSG_INTERNAL_ERROR,
@ -2090,7 +2094,7 @@ int CLIENT_STATE::detach_project(PROJECT* project) {
// delete account file
//
get_account_filename(project->master_url, path);
get_account_filename(project->master_url, path, sizeof(path));
retval = boinc_delete_file(path);
if (retval) {
msg_printf(project, MSG_INTERNAL_ERROR,

View File

@ -37,6 +37,10 @@
#include <cstring>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "error_numbers.h"
#include "filesys.h"
#include "log_flags.h"
@ -598,7 +602,7 @@ int FILE_INFO::merge_info(FILE_INFO& new_info) {
if (max_nbytes <= 0 && new_info.max_nbytes) {
max_nbytes = new_info.max_nbytes;
sprintf(buf, " <max_nbytes>%.0f</max_nbytes>\n", new_info.max_nbytes);
snprintf(buf, sizeof(buf), " <max_nbytes>%.0f</max_nbytes>\n", new_info.max_nbytes);
}
// replace existing URLs with new ones
@ -668,7 +672,7 @@ bool FILE_INFO::had_failure(int& failnum) {
void FILE_INFO::failure_message(string& s) {
char buf[1024];
sprintf(buf,
snprintf(buf, sizeof(buf),
"<file_xfer_error>\n"
" <file_name>%s</file_name>\n"
" <error_code>%d (%s)</error_code>\n",
@ -677,7 +681,7 @@ void FILE_INFO::failure_message(string& s) {
);
s = buf;
if (error_msg.size()) {
sprintf(buf,
snprintf(buf, sizeof(buf),
" <error_message>%s</error_message>\n",
error_msg.c_str()
);

View File

@ -59,7 +59,7 @@ int PROJECT::write_account_file() {
FILE* f;
int retval;
get_account_filename(master_url, path);
get_account_filename(master_url, path, sizeof(path));
f = boinc_fopen(TEMP_ACCT_FILE_NAME, "w");
if (!f) return ERR_FOPEN;
@ -202,7 +202,7 @@ int PROJECT::parse_account_file_venue() {
bool in_right_venue = false, btemp;
double dtemp;
get_account_filename(master_url, path);
get_account_filename(master_url, path, sizeof(path));
FILE* in = boinc_fopen(path, "r");
if (!in) return ERR_FOPEN;
@ -291,7 +291,7 @@ int PROJECT::parse_account_file() {
int retval;
FILE* f;
get_account_filename(master_url, path);
get_account_filename(master_url, path, sizeof(path));
f = boinc_fopen(path, "r");
if (!f) return ERR_FOPEN;
retval = parse_account(f);
@ -464,7 +464,7 @@ int PROJECT::write_statistics_file() {
FILE* f;
int retval;
get_statistics_filename(master_url, path);
get_statistics_filename(master_url, path, sizeof(path));
f = boinc_fopen(TEMP_STATS_FILE_NAME, "w");
if (!f) return ERR_FOPEN;
fprintf(f,
@ -551,7 +551,7 @@ int CLIENT_STATE::add_project(
return retval;
}
get_account_filename(canonical_master_url, path);
get_account_filename(canonical_master_url, path, sizeof(path));
f = boinc_fopen(path, "r");
if (!f) {
delete project;

View File

@ -54,6 +54,10 @@
#include <ctime>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "error_numbers.h"
#include "file_names.h"
#include "filesys.h"
@ -190,7 +194,7 @@ int cpu_benchmarks(BENCHMARK_DESC* bdp) {
#endif
if (retval) {
bdp->error = true;
sprintf(bdp->error_str, "FP benchmark ran only %f sec; ignoring", fp_time);
snprintf(bdp->error_str, sizeof(bdp->error_str), "FP benchmark ran only %f sec; ignoring", fp_time);
return 0;
}
#ifdef _WIN32
@ -204,7 +208,7 @@ int cpu_benchmarks(BENCHMARK_DESC* bdp) {
retval = dhrystone(vax_mips, int_loops, int_time, MIN_CPU_TIME);
if (retval) {
bdp->error = true;
sprintf(bdp->error_str, "Integer benchmark ran only %f sec; ignoring", int_time);
snprintf(bdp->error_str, sizeof(bdp->error_str), "Integer benchmark ran only %f sec; ignoring", int_time);
return 0;
}
host_info.p_iops = vax_mips*1e6;

View File

@ -30,6 +30,10 @@
#include <sys/types.h>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "md5_file.h"
#include "crypt.h"
#include "str_replace.h"
@ -188,7 +192,7 @@ int FILE_INFO::verify_file(
//
if (download_gzipped && !boinc_file_exists(pathname)) {
char gzpath[MAXPATHLEN];
sprintf(gzpath, "%s.gz", pathname);
snprintf(gzpath, sizeof(gzpath), "%s.gz", pathname);
if (boinc_file_exists(gzpath) ) {
if (allow_async && nbytes > ASYNC_FILE_THRESHOLD) {
ASYNC_VERIFY* avp = new ASYNC_VERIFY;
@ -414,8 +418,8 @@ bool CLIENT_STATE::create_and_delete_pers_file_xfers() {
if (fip->download_gzipped) {
char path[MAXPATHLEN], from_path[MAXPATHLEN], to_path[MAXPATHLEN];
get_pathname(fip, path, sizeof(path));
sprintf(from_path, "%s.gzt", path);
sprintf(to_path, "%s.gz", path);
snprintf(from_path, sizeof(from_path), "%s.gzt", path);
snprintf(to_path, sizeof(to_path), "%s.gz", path);
boinc_rename(from_path, to_path);
}

View File

@ -24,6 +24,10 @@
#include <string>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "parse.h"
#include "url.h"
#include "filesys.h"
@ -52,10 +56,10 @@ static bool cmp(NOTICE n1, NOTICE n2) {
return (strcmp(n1.guid, n2.guid) > 0);
}
static void project_feed_list_file_name(PROJ_AM* p, char* buf) {
static void project_feed_list_file_name(PROJ_AM* p, char* buf, int len) {
char url[256];
escape_project_url(p->master_url, url);
sprintf(buf, "notices/feeds_%s.xml", url);
snprintf(buf, len, "notices/feeds_%s.xml", url);
}
// parse feed descs from scheduler reply or feed list file
@ -95,7 +99,7 @@ static void write_rss_feed_descs(MIOFILE& fout, vector<RSS_FEED>& feeds) {
static void write_project_feed_list(PROJ_AM* p) {
char buf[256];
project_feed_list_file_name(p, buf);
project_feed_list_file_name(p, buf, sizeof(buf));
FILE* f = fopen(buf, "w");
if (!f) return;
MIOFILE fout;
@ -496,7 +500,7 @@ void NOTICES::write_archive(RSS_FEED* rfp) {
char path[MAXPATHLEN];
if (rfp) {
rfp->archive_file_name(path);
rfp->archive_file_name(path, sizeof(path));
} else {
safe_strcpy(path, NOTICES_DIR"/archive.xml");
}
@ -609,16 +613,16 @@ void NOTICES::write(int seqno, GUI_RPC_CONN& grc, bool public_only) {
///////////// RSS_FEED ////////////////
void RSS_FEED::feed_file_name(char* path) {
void RSS_FEED::feed_file_name(char* path, int len) {
char buf[256];
escape_project_url(url_base, buf);
sprintf(path, NOTICES_DIR"/%s.xml", buf);
snprintf(path, len, NOTICES_DIR"/%s.xml", buf);
}
void RSS_FEED::archive_file_name(char* path) {
void RSS_FEED::archive_file_name(char* path, int len) {
char buf[256];
escape_project_url(url_base, buf);
sprintf(path, NOTICES_DIR"/archive_%s.xml", buf);
snprintf(path, len, NOTICES_DIR"/archive_%s.xml", buf);
}
// read and parse the contents of the archive file;
@ -626,7 +630,7 @@ void RSS_FEED::archive_file_name(char* path) {
//
int RSS_FEED::read_archive_file() {
char path[MAXPATHLEN];
archive_file_name(path);
archive_file_name(path, sizeof(path));
return notices.read_archive_file(path, this);
}
@ -752,9 +756,9 @@ int RSS_FEED::parse_items(XML_PARSER& xp, int& nitems) {
void RSS_FEED::delete_files() {
char path[MAXPATHLEN];
feed_file_name(path);
feed_file_name(path, sizeof(path));
boinc_delete_file(path);
archive_file_name(path);
archive_file_name(path, sizeof(path));
boinc_delete_file(path);
}
@ -770,14 +774,14 @@ RSS_FEED_OP::RSS_FEED_OP() {
//
bool RSS_FEED_OP::poll() {
unsigned int i;
char file_name[256];
if (gstate.gui_http.is_busy()) return false;
if (gstate.network_suspended) return false;
for (i=0; i<rss_feeds.feeds.size(); i++) {
RSS_FEED& rf = rss_feeds.feeds[i];
if (gstate.now > rf.next_poll_time) {
rf.next_poll_time = gstate.now + rf.poll_interval;
char filename[256];
rf.feed_file_name(filename);
rf.feed_file_name(file_name, sizeof(file_name));
rfp = &rf;
if (log_flags.notice_debug) {
msg_printf(0, MSG_INFO,
@ -786,7 +790,7 @@ bool RSS_FEED_OP::poll() {
}
char url[1024];
safe_strcpy(url, rf.url);
gstate.gui_http.do_rpc(this, url, filename, true);
gstate.gui_http.do_rpc(this, url, file_name, true);
break;
}
}
@ -796,7 +800,7 @@ bool RSS_FEED_OP::poll() {
// handle a completed RSS feed fetch
//
void RSS_FEED_OP::handle_reply(int http_op_retval) {
char filename[256];
char file_name[256];
int nitems;
if (!rfp) return; // op was canceled
@ -816,11 +820,11 @@ void RSS_FEED_OP::handle_reply(int http_op_retval) {
);
}
rfp->feed_file_name(filename);
FILE* f = fopen(filename, "r");
rfp->feed_file_name(file_name, sizeof(file_name));
FILE* f = fopen(file_name, "r");
if (!f) {
msg_printf(0, MSG_INTERNAL_ERROR,
"RSS feed file '%s' not found", filename
"RSS feed file '%s' not found", file_name
);
return;
}
@ -847,7 +851,7 @@ static void init_proj_am(PROJ_AM* p) {
MIOFILE fin;
char path[MAXPATHLEN];
project_feed_list_file_name(p, path);
project_feed_list_file_name(p, path, sizeof(path));
f = fopen(path, "r");
if (f) {
fin.init_file(f);
@ -987,6 +991,6 @@ void RSS_FEEDS::write_feed_list() {
void delete_project_notice_files(PROJECT* p) {
char path[MAXPATHLEN];
project_feed_list_file_name(p, path);
project_feed_list_file_name(p, path, sizeof(path));
boinc_delete_file(path);
}

View File

@ -114,8 +114,8 @@ struct RSS_FEED {
void write(MIOFILE&);
int parse_desc(XML_PARSER&);
int parse_items(XML_PARSER&, int&);
void feed_file_name(char*);
void archive_file_name(char*);
void feed_file_name(char*, int);
void archive_file_name(char*, int);
int read_archive_file();
void delete_files();
};

View File

@ -34,6 +34,10 @@
#include <set>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "crypt.h"
#include "error_numbers.h"
#include "file_names.h"
@ -334,17 +338,17 @@ int CLIENT_STATE::make_scheduler_request(PROJECT* p) {
int rt = rp->avp->gpu_usage.rsc_type;
if (rt) {
if (rt == rsc_index(GPU_TYPE_NVIDIA)) {
sprintf(buf,
snprintf(buf, sizeof(buf),
" <ncudas>%f</ncudas>\n",
rp->avp->gpu_usage.usage
);
} else if (rt == rsc_index(GPU_TYPE_ATI)) {
sprintf(buf,
snprintf(buf, sizeof(buf),
" <natis>%f</natis>\n",
rp->avp->gpu_usage.usage
);
} else if (rt == rsc_index(GPU_TYPE_INTEL)) {
sprintf(buf,
snprintf(buf, sizeof(buf),
" <nintel_gpus>%f</nintel_gpus>\n",
rp->avp->gpu_usage.usage
);
@ -573,7 +577,7 @@ int CLIENT_STATE::handle_scheduler_reply(
if (log_flags.sched_ops) {
if (work_fetch.requested_work()) {
sprintf(buf, ": got %d new tasks", (int)sr.results.size());
snprintf(buf, sizeof(buf), ": got %d new tasks", (int)sr.results.size());
} else {
safe_strcpy(buf, "");
}
@ -1151,7 +1155,7 @@ void CLIENT_STATE::check_project_timeout() {
if (p->possibly_backed_off && now > p->min_rpc_time) {
p->possibly_backed_off = false;
char buf[256];
sprintf(buf, "Backoff ended for %s", p->get_project_name());
snprintf(buf, sizeof(buf), "Backoff ended for %s", p->get_project_name());
request_work_fetch(buf);
}
}

View File

@ -24,6 +24,10 @@
#include <errno.h>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "error_numbers.h"
#include "filesys.h"
#include "md5_file.h"
@ -823,7 +827,7 @@ void CLIENT_STATE::check_anonymous() {
for (i=0; i<projects.size(); i++) {
PROJECT* p = projects[i];
sprintf(path, "%s/%s", p->project_dir(), APP_INFO_FILE_NAME);
snprintf(path, sizeof(path), "%s/%s", p->project_dir(), APP_INFO_FILE_NAME);
f = fopen(path, "r");
if (!f) continue;
msg_printf(p, MSG_INFO,

View File

@ -27,6 +27,10 @@
#include <cstring>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "error_numbers.h"
#include "file_names.h"
#include "filesys.h"
@ -68,7 +72,7 @@ int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) {
*p = '_';
t = atoi(p+1);
sprintf(path, "%s/%s", project->project_dir(), fname);
snprintf(path, sizeof(path), "%s/%s", project->project_dir(), fname);
retval = read_file_malloc(path, file_contents);
if (retval) {
if (log_flags.trickle_debug) {
@ -99,7 +103,7 @@ int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) {
// append .sent to filename, so we'll know which ones to delete later
//
if (!ends_with(fname, ".sent")) {
sprintf(newpath, "%s/%s.sent", project->project_dir(), fname);
snprintf(newpath, sizeof(newpath), "%s/%s.sent", project->project_dir(), fname);
boinc_rename(path, newpath);
}
}
@ -120,7 +124,7 @@ int CLIENT_STATE::remove_trickle_files(PROJECT* project) {
safe_strcpy(fname, fn.c_str());
if (!starts_with(fname, "trickle_up")) continue;
if (!ends_with(fname, ".sent")) continue;
sprintf(path, "%s/%s", project->project_dir(), fname);
snprintf(path, sizeof(path), "%s/%s", project->project_dir(), fname);
delete_project_owned_file(path, true);
}
return 0;
@ -144,7 +148,7 @@ int CLIENT_STATE::handle_trickle_down(PROJECT* project, FILE* in) {
if (!rp) return ERR_NULL;
ACTIVE_TASK* atp = lookup_active_task_by_result(rp);
if (!atp) return ERR_NULL;
sprintf(path, "%s/trickle_down_%d", atp->slot_dir, send_time);
snprintf(path, sizeof(path), "%s/trickle_down_%d", atp->slot_dir, send_time);
FILE* f = fopen(path, "w");
if (!f) return ERR_FOPEN;
fputs(body.c_str(), f);
@ -177,9 +181,9 @@ bool trickle_up_poll() {
}
static void trickle_up_request_message(
PROJECT* p, const char* msg, char* result_name, int t, char* buf
PROJECT* p, const char* msg, char* result_name, int t, char* buf, int len
) {
sprintf(buf,
snprintf(buf, len,
"<scheduler_request>\n"
" <authenticator>%s</authenticator>\n"
" <hostid>%d</hostid>\n"
@ -212,9 +216,10 @@ void send_replicated_trickles(
PROJECT* p, const char* msg, char* result_name, int now
) {
if (!p->trickle_up_ops.size()) return;
char *buf = (char*)malloc(strlen(msg) + 4096);
int trickle_len = strlen(msg) + 4096;
char *buf = (char*)malloc(trickle_len);
if (!buf) return;
trickle_up_request_message(p, msg, result_name, now, buf);
trickle_up_request_message(p, msg, result_name, now, buf, trickle_len);
for (unsigned int i=0; i<p->trickle_up_ops.size(); i++) {
TRICKLE_UP_OP *t = p->trickle_up_ops[i];
if (t->gui_http->is_busy()) {

View File

@ -261,10 +261,10 @@ void delete_old_slot_dirs() {
dir_close(dirp);
}
void get_account_filename(char* master_url, char* path) {
void get_account_filename(char* master_url, char* path, int len) {
char buf[1024];
escape_project_url(master_url, buf);
sprintf(path, "account_%s.xml", buf);
snprintf(path, len, "account_%s.xml", buf);
}
static bool bad_account_filename(const char* filename) {
@ -315,10 +315,10 @@ bool is_statistics_file(const char* filename) {
return true;
}
void get_statistics_filename(char* master_url, char* path) {
void get_statistics_filename(char* master_url, char* path, int len) {
char buf[256];
escape_project_url(master_url, buf);
sprintf(path, "statistics_%s.xml", buf);
snprintf(path, len, "statistics_%s.xml", buf);
}
bool is_image_file(const char* filename) {

View File

@ -37,10 +37,10 @@ extern int make_project_dir(PROJECT&);
extern int remove_project_dir(PROJECT&);
extern int make_slot_dir(int);
extern void delete_old_slot_dirs();
extern void get_account_filename(char* master_url, char* path);
extern void get_account_filename(char* master_url, char* path, int len);
extern bool is_account_file(const char*);
extern bool is_statistics_file(const char*);
extern void get_statistics_filename(char* master_url, char* path);
extern void get_statistics_filename(char* master_url, char* path, int len);
extern bool is_image_file(const char*);
extern void get_sched_request_filename(PROJECT&, char*, int len);

View File

@ -23,6 +23,10 @@
#include "config.h"
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "error_numbers.h"
#include "str_replace.h"
#include "file_names.h"
@ -106,7 +110,7 @@ int FILE_XFER::init_upload(FILE_INFO& file_info) {
}
if (file_info.upload_offset < 0) {
bytes_xferred = 0;
sprintf(header,
snprintf(header, sizeof(header),
"<data_server_request>\n"
" <core_client_major_version>%d</core_client_major_version>\n"
" <core_client_minor_version>%d</core_client_minor_version>\n"
@ -124,7 +128,7 @@ int FILE_XFER::init_upload(FILE_INFO& file_info) {
);
} else {
bytes_xferred = file_info.upload_offset;
sprintf(header,
snprintf(header, sizeof(header),
"<data_server_request>\n"
" <core_client_major_version>%d</core_client_major_version>\n"
" <core_client_minor_version>%d</core_client_minor_version>\n"

View File

@ -160,7 +160,7 @@ void COPROC_ATI::get(
void* callib = dlopen("libaticalrt.so", RTLD_NOW);
if (!callib) {
sprintf(buf, "ATI: %s", dlerror());
snprintf(buf, sizeof(buf), "ATI: %s", dlerror());
warnings.push_back(buf);
return;
}
@ -202,19 +202,19 @@ void COPROC_ATI::get(
retval = (*__calInit)();
if (retval != CAL_RESULT_OK) {
sprintf(buf, "calInit() returned %d", retval);
snprintf(buf, sizeof(buf), "calInit() returned %d", retval);
warnings.push_back(buf);
goto leave;
}
retval = (*__calDeviceGetCount)(&numDevices);
if (retval != CAL_RESULT_OK) {
sprintf(buf, "calDeviceGetCount() returned %d", retval);
snprintf(buf, sizeof(buf), "calDeviceGetCount() returned %d", retval);
warnings.push_back(buf);
goto leave;
}
retval = (*__calGetVersion)(&cal_major, &cal_minor, &cal_imp);
if (retval != CAL_RESULT_OK) {
sprintf(buf, "calGetVersion() returned %d", retval);
snprintf(buf, sizeof(buf), "calGetVersion() returned %d", retval);
warnings.push_back(buf);
goto leave;
}
@ -227,13 +227,13 @@ void COPROC_ATI::get(
for (CALuint i=0; i<numDevices; i++) {
retval = (*__calDeviceGetInfo)(&info, i);
if (retval != CAL_RESULT_OK) {
sprintf(buf, "calDeviceGetInfo() returned %d", retval);
snprintf(buf, sizeof(buf), "calDeviceGetInfo() returned %d", retval);
warnings.push_back(buf);
goto leave;
}
retval = (*__calDeviceGetAttribs)(&attribs, i);
if (retval != CAL_RESULT_OK) {
sprintf(buf, "calDeviceGetAttribs() returned %d", retval);
snprintf(buf, sizeof(buf), "calDeviceGetAttribs() returned %d", retval);
warnings.push_back(buf);
goto leave;
}
@ -372,7 +372,7 @@ void COPROC_ATI::get(
cc.attribs = attribs;
cc.info = info;
safe_strcpy(cc.name, gpu_name.c_str());
sprintf(cc.version, "%d.%d.%d", cal_major, cal_minor, cal_imp);
snprintf(cc.version, sizeof(cc.version), "%d.%d.%d", cal_major, cal_minor, cal_imp);
cc.amdrt_detected = amdrt_detected;
cc.atirt_detected = atirt_detected;
cc.device_num = i;

View File

@ -50,6 +50,10 @@
#endif
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "error_numbers.h"
#include "filesys.h"
#include "network.h"
@ -86,7 +90,7 @@ int GUI_RPC_CONN::handle_auth2(char* buf, MIOFILE& fout) {
auth_failure(fout);
return ERR_AUTHENTICATOR;
}
sprintf(buf2, "%s%s", nonce, gstate.gui_rpcs.password);
snprintf(buf2, sizeof(buf2), "%s%s", nonce, gstate.gui_rpcs.password);
md5_block((const unsigned char*)buf2, (int)strlen(buf2), nonce_hash_correct);
if (strcmp(nonce_hash, nonce_hash_correct)) {
auth_failure(fout);
@ -1429,7 +1433,8 @@ int GUI_RPC_CONN::handle_rpc() {
request_msg[request_nbytes] = 0;
if (!strncmp(request_msg, "OPTIONS", 7)) {
char buf[1024];
sprintf(buf, "HTTP/1.1 200 OK\n"
snprintf(buf, sizeof(buf),
"HTTP/1.1 200 OK\n"
"Server: BOINC client\n"
"Access-Control-Allow-Origin: *\n"
"Access-Control-Allow-Methods: POST, GET, OPTIONS\n"
@ -1505,7 +1510,7 @@ int GUI_RPC_CONN::handle_rpc() {
mout.get_buf(p, n);
if (http_request) {
char buf[1024];
sprintf(buf,
snprintf(buf, sizeof(buf),
"HTTP/1.1 200 OK\n"
"Date: Fri, 31 Dec 1999 23:59:59 GMT\n"
"Server: BOINC client\n"

View File

@ -41,6 +41,10 @@
#endif
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#ifdef __APPLE__
#include <Carbon/Carbon.h>
#endif
@ -68,7 +72,7 @@ int HOST_INFO::get_local_network_info() {
char buf[256];
make_random_string("", buf);
buf[8] = 0;
sprintf(domain_name, "android_%s", buf);
snprintf(domain_name, sizeof(domain_name), "android_%s", buf);
return 0;
#endif
@ -107,11 +111,13 @@ void HOST_INFO::make_random_string(const char* salt, char* out) {
char buf[1024];
#ifdef ANDROID
sprintf(buf, "%f%s%s%f%s",
snprintf(buf, sizeof(buf),
"%f%s%s%f%s",
dtime(), domain_name, ip_addr, d_free, salt
);
#else
sprintf(buf, "%d%.15e%s%s%f%s",
snprintf(buf, sizeof(buf),
"%d%.15e%s%s%f%s",
getpid(), dtime(), domain_name, ip_addr, d_free, salt
);
#endif

View File

@ -20,8 +20,9 @@
#ifdef _WIN32
#include "boinc_win.h"
#ifdef _MSC_VER
#define unlink _unlink
#define chdir _chdir
#define unlink _unlink
#define chdir _chdir
#define snprintf _snprintf
#endif
#else
#include "config.h"
@ -70,13 +71,14 @@ static bool got_expectation_failed = false;
static void get_user_agent_string() {
if (g_user_agent_string[0]) return;
sprintf(g_user_agent_string, "BOINC client (%s %d.%d.%d)",
snprintf(g_user_agent_string, sizeof(g_user_agent_string),
"BOINC client (%s %d.%d.%d)",
gstate.get_primary_platform(),
BOINC_MAJOR_VERSION, BOINC_MINOR_VERSION, BOINC_RELEASE
);
if (strlen(gstate.client_brand)) {
char buf[256];
sprintf(buf, " (%s)", gstate.client_brand);
snprintf(buf, sizeof(buf), " (%s)", gstate.client_brand);
safe_strcat(g_user_agent_string, buf);
}
}
@ -357,7 +359,9 @@ int HTTP_OP::init_post2(
file_offset = offset;
retval = file_size(infile, size);
if (retval) {
printf("HTTP::init_post2: couldn't get file size\n");
if (log_flags.http_debug) {
msg_printf(project, MSG_INFO, "[http] HTTP::init_post2: couldn't get file size");
}
return retval; // this will be 0 or ERR_NOT_FOUND
}
content_length = (int)size - (int)offset;
@ -437,7 +441,7 @@ int HTTP_OP::libcurl_exec(
} else {
// always want an outfile for the server response, delete when op done
bTempOutfile = true;
sprintf(outfile, "http_temp_%d", outfile_seqno++);
snprintf(outfile, sizeof(outfile), "http_temp_%d", outfile_seqno++);
}
curlEasy = curl_easy_init(); // get a curl_easy handle to use
@ -603,7 +607,7 @@ int HTTP_OP::libcurl_exec(
pcurlList = curl_slist_append(pcurlList, g_content_type);
if (strlen(gstate.language)) {
sprintf(buf, "Accept-Language: %s", gstate.language);
snprintf(buf, sizeof(buf), "Accept-Language: %s", gstate.language);
pcurlList = curl_slist_append(pcurlList, buf);
}
@ -611,7 +615,7 @@ int HTTP_OP::libcurl_exec(
//
if (!is_post && offset>0.0f) {
file_offset = offset;
sprintf(buf, "Range: bytes=%.0f-", offset);
snprintf(buf, sizeof(buf), "Range: bytes=%.0f-", offset);
pcurlList = curl_slist_append(pcurlList, buf);
}
@ -852,7 +856,10 @@ void HTTP_OP::setup_proxy_session(bool no_proxy) {
} else {
curl_easy_setopt(curlEasy, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
}
sprintf(m_curl_user_credentials, "%s:%s", pi.http_user_name, pi.http_user_passwd);
snprintf(m_curl_user_credentials, sizeof(m_curl_user_credentials),
"%s:%s",
pi.http_user_name, pi.http_user_passwd
);
curl_easy_setopt(curlEasy, CURLOPT_PROXYUSERPWD, m_curl_user_credentials);
}
@ -868,7 +875,10 @@ void HTTP_OP::setup_proxy_session(bool no_proxy) {
if (
strlen(pi.socks5_user_passwd) || strlen(pi.socks5_user_name)
) {
sprintf(m_curl_user_credentials, "%s:%s", pi.socks5_user_name, pi.socks5_user_passwd);
snprintf(m_curl_user_credentials, sizeof(m_curl_user_credentials),
"%s:%s",
pi.socks5_user_name, pi.socks5_user_passwd
);
curl_easy_setopt(curlEasy, CURLOPT_PROXYUSERPWD, m_curl_user_credentials);
curl_easy_setopt(curlEasy, CURLOPT_PROXYAUTH, CURLAUTH_ANY & ~CURLAUTH_NTLM);
}

View File

@ -20,7 +20,8 @@
#ifdef _WIN32
#include "boinc_win.h"
#ifdef _MSC_VER
#define chdir _chdir
#define chdir _chdir
#define snprintf _snprintf
#endif
#else
#include "config.h"
@ -138,7 +139,7 @@ static void show_exclude_gpu(EXCLUDE_GPU& e) {
if (e.device_num < 0) {
safe_strcpy(dev, "all");
} else {
sprintf(dev, "%d", e.device_num);
snprintf(dev, sizeof(dev), "%d", e.device_num);
}
msg_printf(p, MSG_INFO,
"Config: excluded GPU. Type: %s. App: %s. Device: %s",

View File

@ -18,6 +18,10 @@
#include <boinc_win.h>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include <string.h>
#include "str_replace.h"
@ -670,7 +674,7 @@ void PROJECT::delete_project_file_symlinks() {
for (i=0; i<project_files.size(); i++) {
FILE_REF& fref = project_files[i];
sprintf(path, "%s/%s", project_dir(), fref.open_name);
snprintf(path, sizeof(path), "%s/%s", project_dir(), fref.open_name);
delete_project_owned_file(path, false);
}
}
@ -730,8 +734,8 @@ int PROJECT::write_symlink_for_project_file(FILE_INFO* fip) {
for (i=0; i<project_files.size(); i++) {
FILE_REF& fref = project_files[i];
if (fref.file_info != fip) continue;
sprintf(link_path, "%s/%s", project_dir(), fref.open_name);
sprintf(file_path, "%s/%s", project_dir(), fip->name);
snprintf(link_path, sizeof(link_path), "%s/%s", project_dir(), fref.open_name);
snprintf(file_path, sizeof(file_path), "%s/%s", project_dir(), fip->name);
make_soft_link(this, link_path, file_path);
}
return 0;
@ -888,7 +892,7 @@ const char* PROJECT::project_dir() {
if (_project_dir[0] == 0) {
char buf[1024];
escape_project_url(master_url, buf);
sprintf(_project_dir, "%s/%s", PROJECTS_DIR, buf);
snprintf(_project_dir, sizeof(_project_dir), "%s/%s", PROJECTS_DIR, buf);
}
return _project_dir;
}

View File

@ -15,7 +15,16 @@
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#ifdef _WIN32
#include "boinc_win.h"
#else
#include "config.h"
#include <math.h>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "str_replace.h"
#include "parse.h"
@ -388,14 +397,14 @@ int RESULT::write_gui(MIOFILE& out) {
//
if (avp->gpu_usage.rsc_type) {
if (avp->gpu_usage.usage == 1) {
sprintf(resources,
snprintf(resources, sizeof(resources),
"%.3g %s + 1 %s",
avp->avg_ncpus,
cpu_string(avp->avg_ncpus),
rsc_name_long(avp->gpu_usage.rsc_type)
);
} else {
sprintf(resources,
snprintf(resources, sizeof(resources),
"%.3g %s + %.3g %ss",
avp->avg_ncpus,
cpu_string(avp->avg_ncpus),
@ -404,13 +413,15 @@ int RESULT::write_gui(MIOFILE& out) {
);
}
} else if (avp->missing_coproc) {
sprintf(resources, "%.3g %s + %s GPU (missing)",
snprintf(resources, sizeof(resources),
"%.3g %s + %s GPU (missing)",
avp->avg_ncpus,
cpu_string(avp->avg_ncpus),
avp->missing_coproc_name
);
} else if (!project->non_cpu_intensive && (avp->avg_ncpus != 1)) {
sprintf(resources, "%.3g %s",
snprintf(resources, sizeof(resources),
"%.3g %s",
avp->avg_ncpus,
cpu_string(avp->avg_ncpus)
);

View File

@ -42,6 +42,10 @@
#include "config.h"
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "client_msgs.h"
#include "client_state.h"
#include "coproc.h"
@ -50,15 +54,16 @@
using std::vector;
inline void rsc_string(RESULT* rp, char* buf) {
inline void rsc_string(RESULT* rp, char* buf, int len) {
APP_VERSION* avp = rp->avp;
if (avp->gpu_usage.rsc_type) {
sprintf(buf, "%.2f CPU + %.2f %s",
snprintf(buf, len,
"%.2f CPU + %.2f %s",
avp->avg_ncpus, avp->gpu_usage.usage,
rsc_name_long(avp->gpu_usage.rsc_type)
);
} else {
sprintf(buf, "%.2f CPU", avp->avg_ncpus);
snprintf(buf, len, "%.2f CPU", avp->avg_ncpus);
}
}
@ -273,7 +278,7 @@ void RR_SIM::pick_jobs_to_run(double reltime) {
adjust_rec_sched(rp);
if (log_flags.rrsim_detail && !rp->already_selected) {
char buf[256];
rsc_string(rp, buf);
rsc_string(rp, buf, sizeof(buf));
msg_printf(rp->project, MSG_INFO,
"[rr_sim_detail] %.2f: starting %s (%s) (%.2fG/%.2fG)",
reltime, rp->name, buf, rp->rrsim_flops_left/1e9, rp->rrsim_flops/1e9
@ -443,7 +448,7 @@ void RR_SIM::simulate() {
pbest = rpbest->project;
if (log_flags.rr_simulation) {
char buf[256];
rsc_string(rpbest, buf);
rsc_string(rpbest, buf, sizeof(buf));
msg_printf(pbest, MSG_INFO,
"[rr_sim] %.2f: %s finishes (%s) (%.2fG/%.2fG)",
sim_now + delta_t - gstate.now,

View File

@ -29,6 +29,10 @@
#include <grp.h>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "error_numbers.h"
#include "file_names.h"
#include "util.h"
@ -61,7 +65,7 @@ int switcher_exec(const char *util_filename, const char* cmdline) {
int retval;
std::string output_out, output_err;
sprintf(util_path, "%s/%s", SWITCHER_DIR, util_filename);
snprintf(util_path, sizeof(util_path), "%s/%s", SWITCHER_DIR, util_filename);
argv[0] = const_cast<char*>(util_filename);
// Make a copy of cmdline because parse_command_line modifies it
safe_strcpy(command, cmdline);
@ -171,7 +175,7 @@ int kill_via_switcher(int pid) {
// client is running as user boinc_master,
// we cannot send a signal directly, so use switcher.
//
sprintf(cmd, "/bin/kill kill -s KILL %d", pid);
snprintf(cmd, sizeof(cmd), "/bin/kill kill -s KILL %d", pid);
return switcher_exec(SWITCHER_FILE_NAME, cmd);
}
@ -188,7 +192,7 @@ int remove_project_owned_file_or_dir(const char* path) {
char cmd[1024];
if (g_use_sandbox) {
sprintf(cmd, "/bin/rm rm -fR \"%s\"", path);
snprintf(cmd, sizeof(cmd), "/bin/rm rm -fR \"%s\"", path);
if (switcher_exec(SWITCHER_FILE_NAME, cmd)) {
return ERR_UNLINK;
} else {
@ -342,7 +346,7 @@ int client_clean_out_dir(
if (except && !strcmp(except, filename)) {
continue;
}
sprintf(path, "%s/%s", dirpath, filename);
snprintf(path, sizeof(path), "%s/%s", dirpath, filename);
if (is_dir(path)) {
retval = client_clean_out_dir(path, NULL);
if (retval) final_retval = retval;

View File

@ -27,6 +27,10 @@
#include <ctime>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "error_numbers.h"
#include "filesys.h"
#include "parse.h"
@ -102,7 +106,7 @@ int SCHEDULER_OP::init_op_project(PROJECT* p, int r) {
if (p->scheduler_urls.size() == 0) {
retval = init_master_fetch(p);
if (retval) {
sprintf(err_msg,
snprintf(err_msg, sizeof(err_msg),
"Scheduler list fetch initialization failed: %d\n", retval
);
project_rpc_backoff(p, err_msg);
@ -123,7 +127,7 @@ int SCHEDULER_OP::init_op_project(PROJECT* p, int r) {
retval = start_rpc(p);
}
if (retval) {
sprintf(err_msg,
snprintf(err_msg, sizeof(err_msg),
"scheduler request to %s failed: %s\n",
p->get_scheduler_url(url_index, url_random), boincerror(retval)
);
@ -161,7 +165,7 @@ void SCHEDULER_OP::project_rpc_backoff(PROJECT* p, const char *reason_msg) {
}
if (p->master_fetch_failures >= gstate.master_fetch_retry_cap) {
sprintf(buf,
snprintf(buf, sizeof(buf),
"%d consecutive failures fetching scheduler list",
p->master_fetch_failures
);
@ -459,7 +463,7 @@ bool SCHEDULER_OP::poll() {
// master file fetch failed.
//
char buf[256];
sprintf(buf, "Scheduler list fetch failed: %s",
snprintf(buf, sizeof(buf), "Scheduler list fetch failed: %s",
boincerror(http_op.http_op_retval)
);
cur_proj->master_fetch_failures++;

View File

@ -17,6 +17,10 @@
#include "boinc_win.h"
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "diagnostics.h"
#include "error_numbers.h"
#include "filesys.h"
@ -357,7 +361,7 @@ static void windows_detect_autoproxy_settings() {
}
if (log_flags.proxy_debug) {
sprintf_s(buf, "proxy detected %s:%d", purl.host, purl.port);
snprintf(buf, sizeof(buf), "proxy detected %s:%d", purl.host, purl.port);
safe_strcat(msg, buf);
}
}

View File

@ -30,6 +30,10 @@
#endif
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "error_numbers.h"
#include "filesys.h"
#include "parse.h"
@ -221,10 +225,14 @@ void CLIENT_TIME_STATS::update(int suspend_reason, int _gpu_suspend_reason) {
log_append("power_off", last_update);
char buf[256];
#ifndef SIM
sprintf(buf, "platform %s", gstate.get_primary_platform());
snprintf(buf, sizeof(buf),
"platform %s",
gstate.get_primary_platform()
);
log_append(buf, gstate.now);
#endif
sprintf(buf, "version %d.%d.%d",
snprintf(buf, sizeof(buf),
"version %d.%d.%d",
BOINC_MAJOR_VERSION, BOINC_MINOR_VERSION, BOINC_RELEASE
);
log_append(buf, gstate.now);

View File

@ -15,14 +15,17 @@
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#include <cmath>
#include "cpp.h"
#ifdef _WIN32
#include "boinc_win.h"
#else
#include "config.h"
#include <cmath>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "util.h"
@ -299,7 +302,8 @@ void RSC_WORK_FETCH::print_state(const char* name) {
RSC_PROJECT_WORK_FETCH& rpwf = project_state(p);
double bt = rpwf.backoff_time>gstate.now?rpwf.backoff_time-gstate.now:0;
if (bt) {
sprintf(buf, " (resource backoff: %.2f, inc %.2f)",
snprintf(buf, sizeof(buf),
" (resource backoff: %.2f, inc %.2f)",
bt, rpwf.backoff_interval
);
} else {
@ -351,15 +355,22 @@ void PROJECT_WORK_FETCH::rr_init(PROJECT* p) {
void PROJECT_WORK_FETCH::print_state(PROJECT* p) {
char buf[1024], buf2[1024];
if (project_reason) {
sprintf(buf, "can't request work: %s", project_reason_string(p, buf2, sizeof(buf2)));
snprintf(buf, sizeof(buf),
"can't request work: %s",
project_reason_string(p, buf2, sizeof(buf2))
);
} else {
safe_strcpy(buf, "can request work");
}
if (p->min_rpc_time > gstate.now) {
sprintf(buf2, " (%.2f sec)", p->min_rpc_time - gstate.now);
snprintf(buf2, sizeof(buf2),
" (%.2f sec)",
p->min_rpc_time - gstate.now
);
safe_strcat(buf, buf2);
}
msg_printf(p, MSG_INFO, "[work_fetch] REC %.3f prio %.3f %s",
msg_printf(p, MSG_INFO,
"[work_fetch] REC %.3f prio %.3f %s",
rec,
p->sched_priority,
buf
@ -816,12 +827,13 @@ void WORK_FETCH::compute_shares() {
void WORK_FETCH::request_string(char* buf, int len) {
char buf2[256];
sprintf(buf,
snprintf(buf, len,
"[work_fetch] request: CPU (%.2f sec, %.2f inst)",
rsc_work_fetch[0].req_secs, rsc_work_fetch[0].req_instances
);
for (int i=1; i<coprocs.n_rsc; i++) {
sprintf(buf2, " %s (%.2f sec, %.2f inst)",
snprintf(buf2, sizeof(buf2),
" %s (%.2f sec, %.2f inst)",
rsc_name_long(i), rsc_work_fetch[i].req_secs, rsc_work_fetch[i].req_instances
);
strlcat(buf, buf2, len);
@ -1136,7 +1148,8 @@ const char* project_reason_string(PROJECT* p, char* buf, int len) {
return "too many runnable tasks";
case CANT_FETCH_WORK_DONT_NEED:
if (coprocs.n_rsc == 1) {
sprintf(buf, "don't need (%s)",
snprintf(buf, len,
"don't need (%s)",
rsc_project_reason_string(rsc_work_fetch[0].dont_fetch_reason)
);
} else {
@ -1144,7 +1157,8 @@ const char* project_reason_string(PROJECT* p, char* buf, int len) {
x = "don't need (";
for (int i=0; i<coprocs.n_rsc; i++) {
char buf2[256];
sprintf(buf2, "%s: %s",
snprintf(buf2, sizeof(buf2),
"%s: %s",
rsc_name_long(i),
rsc_project_reason_string(rsc_work_fetch[i].dont_fetch_reason)
);