mirror of https://github.com/BOINC/boinc.git
Fix compile warnings in client/ and lib/.
Check returns from fgets(), sscanf() etc. Use %.*s to fix truncation warnings. Fix code formatting. Fix Makefile.linux
This commit is contained in:
parent
3d1d402938
commit
5310652f30
|
@ -6,7 +6,7 @@
|
|||
# make -f Makefile.linux clean all
|
||||
# 3) do the same in this dir
|
||||
|
||||
CC = g++ -I ../ -I ../lib/
|
||||
CC = g++ -O4 -Wall -I ../ -I ../lib/
|
||||
|
||||
PROGS = boinc boinccmd
|
||||
|
||||
|
@ -135,6 +135,7 @@ clean:
|
|||
|
||||
LIBS = ../lib/lib.a \
|
||||
-lpthread \
|
||||
-lX11 -lXss \
|
||||
-lssl -lcrypto \
|
||||
-L /usr/local/lib/ -lcurl -lz -ldl
|
||||
|
||||
|
|
|
@ -289,8 +289,11 @@ void CLIENT_STATE::process_autologin(bool first) {
|
|||
//
|
||||
FILE* f = boinc_fopen(ACCOUNT_DATA_FILENAME, "r");
|
||||
if (!f) return;
|
||||
fgets(buf, 256, f);
|
||||
p = fgets(buf, 256, f);
|
||||
fclose(f);
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
p = strstr(buf, "__");
|
||||
if (!p) {
|
||||
boinc_delete_file(ACCOUNT_DATA_FILENAME);
|
||||
|
|
|
@ -642,11 +642,12 @@ bool ACTIVE_TASK::finish_file_present(int &exit_code) {
|
|||
}
|
||||
p = fgets(buf, sizeof(buf), f);
|
||||
if (p && strlen(buf)) {
|
||||
fgets(buf2, sizeof(buf2), f);
|
||||
msg_printf(result->project,
|
||||
strstr(buf2, "notice")?MSG_USER_ALERT:MSG_INFO,
|
||||
"Message from task: %s", buf
|
||||
);
|
||||
if (fgets(buf2, sizeof(buf2), f)) {
|
||||
msg_printf(result->project,
|
||||
strstr(buf2, "notice")?MSG_USER_ALERT:MSG_INFO,
|
||||
"Message from task: %s", buf
|
||||
);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
|
@ -667,8 +668,12 @@ bool ACTIVE_TASK::temporary_exit_file_present(
|
|||
} else {
|
||||
x = y;
|
||||
}
|
||||
(void) fgets(buf, 256, f); // read the \n
|
||||
(void) fgets(buf, 256, f);
|
||||
char *p = fgets(buf, 256, f); // read the \n
|
||||
p = fgets(buf, 256, f);
|
||||
if (p == NULL) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
strip_whitespace(buf);
|
||||
is_notice = false;
|
||||
if (fgets(buf2, 256, f)) {
|
||||
|
@ -1617,8 +1622,11 @@ void ACTIVE_TASK::read_task_state_file() {
|
|||
FILE* f = boinc_fopen(path, "r");
|
||||
if (!f) return;
|
||||
buf[0] = 0;
|
||||
(void) fread(buf, 1, 4096, f);
|
||||
size_t n = fread(buf, 1, 4096, f);
|
||||
fclose(f);
|
||||
if (n == 0) {
|
||||
return;
|
||||
}
|
||||
buf[4095] = 0;
|
||||
double x;
|
||||
// TODO: use XML parser
|
||||
|
|
|
@ -1065,7 +1065,8 @@ int ACTIVE_TASK::start(bool test) {
|
|||
|
||||
// hook up stderr to a specially-named file
|
||||
//
|
||||
(void) freopen(STDERR_FILE, "a", stderr);
|
||||
if (freopen(STDERR_FILE, "a", stderr) == NULL) {
|
||||
}
|
||||
|
||||
// lower our priority if needed
|
||||
//
|
||||
|
@ -1250,7 +1251,8 @@ void run_test_app() {
|
|||
int retval;
|
||||
|
||||
char buf[256];
|
||||
getcwd(buf, sizeof(buf)); // so we can see where we're running
|
||||
if (getcwd(buf, sizeof(buf)) == NULL) { // so we can see where we're running
|
||||
}
|
||||
|
||||
gstate.run_test_app = true;
|
||||
|
||||
|
|
|
@ -294,8 +294,11 @@ bool HOST_INFO::host_is_running_on_batteries() {
|
|||
);
|
||||
fsys = fopen(path, "r");
|
||||
if (!fsys) continue;
|
||||
(void) fgets(buf, sizeof(buf), fsys);
|
||||
char *p = fgets(buf, sizeof(buf), fsys);
|
||||
fclose(fsys);
|
||||
if (p == NULL) {
|
||||
break;
|
||||
}
|
||||
// AC adapters have type "Mains"
|
||||
if ((strstr(buf, "mains") != NULL) || (strstr(buf, "Mains") != NULL)) {
|
||||
method = SysClass;
|
||||
|
@ -327,7 +330,7 @@ bool HOST_INFO::host_is_running_on_batteries() {
|
|||
int apm_ac_line_status=1;
|
||||
|
||||
// supposedly we're on batteries if the 5th entry is zero.
|
||||
(void) fscanf(fapm, "%10s %d.%d %x %x",
|
||||
int n = fscanf(fapm, "%10s %d.%d %x %x",
|
||||
apm_driver_version,
|
||||
&apm_major_version,
|
||||
&apm_minor_version,
|
||||
|
@ -336,6 +339,7 @@ bool HOST_INFO::host_is_running_on_batteries() {
|
|||
);
|
||||
|
||||
fclose(fapm);
|
||||
if (n != 5) return false;
|
||||
|
||||
return (apm_ac_line_status == 0);
|
||||
}
|
||||
|
@ -346,13 +350,15 @@ bool HOST_INFO::host_is_running_on_batteries() {
|
|||
if (!facpi) return false;
|
||||
|
||||
char buf[128];
|
||||
(void) fgets(buf, sizeof(buf), facpi);
|
||||
char *p = fgets(buf, sizeof(buf), facpi);
|
||||
|
||||
fclose(facpi);
|
||||
if (p == NULL) return false;
|
||||
|
||||
if ((strstr(buf, "state:") != NULL) || (strstr(buf, "Status:") != NULL))
|
||||
if ((strstr(buf, "state:") != NULL) || (strstr(buf, "Status:") != NULL)) {
|
||||
// on batteries if ac adapter is "off-line" (or maybe "offline")
|
||||
return (strstr(buf, "off") != NULL);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -363,8 +369,9 @@ bool HOST_INFO::host_is_running_on_batteries() {
|
|||
if (!fsys) return false;
|
||||
|
||||
int online;
|
||||
(void) fscanf(fsys, "%d", &online);
|
||||
int n = fscanf(fsys, "%d", &online);
|
||||
fclose(fsys);
|
||||
if (n != 1) return false;
|
||||
|
||||
// online is 1 if on AC power, 0 if on battery
|
||||
return (0 == online);
|
||||
|
@ -387,10 +394,12 @@ bool HOST_INFO::host_is_running_on_batteries() {
|
|||
for (devn = 0;; devn++) {
|
||||
mib[2] = devn;
|
||||
if (sysctl(mib, 3, &snsrdev, &sdlen, NULL, 0) == -1) {
|
||||
if (errno == ENXIO)
|
||||
if (errno == ENXIO) {
|
||||
continue;
|
||||
if (errno == ENOENT)
|
||||
}
|
||||
if (errno == ENOENT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!strcmp("acpiac0", snsrdev.xname)) {
|
||||
break;
|
||||
|
@ -401,11 +410,12 @@ bool HOST_INFO::host_is_running_on_batteries() {
|
|||
}
|
||||
|
||||
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
||||
if (s.value)
|
||||
if (s.value) {
|
||||
// AC present
|
||||
return false;
|
||||
else
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -414,11 +424,12 @@ bool HOST_INFO::host_is_running_on_batteries() {
|
|||
size_t len = sizeof(ac);
|
||||
|
||||
if (sysctlbyname("hw.acpi.acline", &ac, &len, NULL, 0) != -1) {
|
||||
if (ac)
|
||||
if (ac) {
|
||||
// AC present
|
||||
return false;
|
||||
else
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -1384,7 +1395,7 @@ int HOST_INFO::get_memory_info() {
|
|||
// return ERR_NOT_FOUND if ldd couldn't be opened or no version information was found
|
||||
//
|
||||
#ifdef __GLIBC__
|
||||
int get_libc_version(string& version, string& extra_info) {
|
||||
int get_libc_version(string& version, string&) {
|
||||
version = string(gnu_get_libc_version());
|
||||
return BOINC_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -719,7 +719,7 @@ void PROJECT::delete_project_file_symlinks() {
|
|||
|
||||
for (i=0; i<project_files.size(); i++) {
|
||||
FILE_REF& fref = project_files[i];
|
||||
snprintf(path, sizeof(path), "%s/%s", project_dir(), fref.open_name);
|
||||
snprintf(path, sizeof(path), "%.*s/%s", DIR_LEN, project_dir(), fref.open_name);
|
||||
delete_project_owned_file(path, false);
|
||||
}
|
||||
}
|
||||
|
@ -779,8 +779,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;
|
||||
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);
|
||||
snprintf(link_path, sizeof(link_path), "%.*s/%s", DIR_LEN, project_dir(), fref.open_name);
|
||||
snprintf(file_path, sizeof(file_path), "%.*s/%s", DIR_LEN, project_dir(), fip->name);
|
||||
make_soft_link(this, link_path, file_path);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# make libraries for Linux client and boinccmd
|
||||
|
||||
CC = g++ -I ../
|
||||
CC = g++ -O4 -Wall -I ../
|
||||
|
||||
all: boinc.a boinc_cmd.a
|
||||
|
||||
|
|
|
@ -215,7 +215,9 @@ int scan_key_hex(FILE* f, KEY* key, int size) {
|
|||
len = size - sizeof(key->bits);
|
||||
for (i=0; i<len; i++) {
|
||||
// coverity[check_return]
|
||||
fscanf(f, "%2x", &n);
|
||||
if (fscanf(f, "%2x", &n) != 1) {
|
||||
return ERR_NULL;
|
||||
}
|
||||
key->data[i] = n;
|
||||
}
|
||||
fs = fscanf(f, ".");
|
||||
|
|
|
@ -792,7 +792,7 @@ void boinc_catch_signal(int signal) {
|
|||
size = backtrace (array, 64);
|
||||
// Anything that calls malloc here (i.e *printf()) will probably fail
|
||||
// so we'll do it the hard way.
|
||||
(void) write(fileno(stderr),"Stack trace (",strlen("Stack trace ("));
|
||||
int retval = write(fileno(stderr),"Stack trace (",strlen("Stack trace ("));
|
||||
char mbuf[10];
|
||||
char *p=mbuf+9;
|
||||
int i=size;
|
||||
|
@ -801,11 +801,12 @@ void boinc_catch_signal(int signal) {
|
|||
*(p--)=i%10+'0';
|
||||
i/=10;
|
||||
}
|
||||
(void) write(fileno(stderr),p+1,strlen(p+1));
|
||||
(void) write(fileno(stderr)," frames):",strlen(" frames):"));
|
||||
retval = write(fileno(stderr),p+1,strlen(p+1));
|
||||
retval = write(fileno(stderr)," frames):",strlen(" frames):"));
|
||||
mbuf[0]=10;
|
||||
(void) write(fileno(stderr),mbuf,1);
|
||||
retval = write(fileno(stderr),mbuf,1);
|
||||
backtrace_symbols_fd(array, size, fileno(stderr));
|
||||
if (retval) {}
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
|
|
@ -1970,26 +1970,38 @@ int RPC_CLIENT::run_benchmarks() {
|
|||
// if slot = -1, start the default screensaver
|
||||
// screensaverLoginUser is the login name of the user running the screensaver
|
||||
//
|
||||
int RPC_CLIENT::run_graphics_app(const char *operation, int& operand, const char *screensaverLoginUser) {
|
||||
int RPC_CLIENT::run_graphics_app(
|
||||
const char *operation, int& operand, const char *screensaverLoginUser
|
||||
) {
|
||||
char buf[256];
|
||||
SET_LOCALE sl;
|
||||
RPC rpc(this);
|
||||
int thePID = -1;
|
||||
bool stop = false;
|
||||
bool test = false;
|
||||
|
||||
snprintf(buf, sizeof(buf), "<run_graphics_app>\n");
|
||||
|
||||
if (!strcmp(operation, "run")) {
|
||||
snprintf(buf, sizeof(buf), "<run_graphics_app>\n<slot>%d</slot>\n<run/>\n<ScreensaverLoginUser>%s</ScreensaverLoginUser>\n", operand, screensaverLoginUser);
|
||||
snprintf(buf, sizeof(buf),
|
||||
"<run_graphics_app>\n<slot>%d</slot>\n<run/>\n<ScreensaverLoginUser>%s</ScreensaverLoginUser>\n",
|
||||
operand, screensaverLoginUser
|
||||
);
|
||||
} else if (!strcmp(operation, "runfullscreen")) {
|
||||
snprintf(buf, sizeof(buf), "<run_graphics_app>\n<slot>%d</slot>\n<runfullscreen/>\n<ScreensaverLoginUser>%s</ScreensaverLoginUser>\n", operand, screensaverLoginUser);
|
||||
snprintf(buf, sizeof(buf),
|
||||
"<run_graphics_app>\n<slot>%d</slot>\n<runfullscreen/>\n<ScreensaverLoginUser>%s</ScreensaverLoginUser>\n",
|
||||
operand, screensaverLoginUser
|
||||
);
|
||||
} else if (!strcmp(operation, "stop")) {
|
||||
snprintf(buf, sizeof(buf), "<run_graphics_app>\n<graphics_pid>%d</graphics_pid>\n<stop/>\n<ScreensaverLoginUser>%s</ScreensaverLoginUser>\n", operand, screensaverLoginUser);
|
||||
stop = true;
|
||||
} else if (!strcmp(operation, "test")) {
|
||||
snprintf(buf, sizeof(buf), "<run_graphics_app>\n<graphics_pid>%d</graphics_pid>\n<test/>\n", operand);
|
||||
test = true;
|
||||
snprintf(buf, sizeof(buf),
|
||||
"<run_graphics_app>\n<graphics_pid>%d</graphics_pid>\n<stop/>\n<ScreensaverLoginUser>%s</ScreensaverLoginUser>\n",
|
||||
operand, screensaverLoginUser
|
||||
);
|
||||
} else if (!strcmp(operation, "test")) {
|
||||
snprintf(buf, sizeof(buf),
|
||||
"<run_graphics_app>\n<graphics_pid>%d</graphics_pid>\n<test/>\n",
|
||||
operand
|
||||
);
|
||||
test = true;
|
||||
} else {
|
||||
operand = -1;
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue