From a8485f3d3f98c041fbf5f6121d952be92b97839b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 9 Jul 2013 10:34:32 -0700 Subject: [PATCH] Various: Fix some compile warnings; from Gianfranco --- api/graphics2_unix.cpp | 5 ++++- client/app_control.cpp | 6 +++--- client/app_start.cpp | 7 +++++-- client/cs_platforms.cpp | 4 ++-- client/gpu_detect.cpp | 0 client/hostinfo_unix.cpp | 11 ++++++----- client/log_flags.cpp | 7 ++++++- client/switcher.cpp | 12 +++++++++--- lib/crypt.cpp | 9 ++++++--- lib/diagnostics.cpp | 8 ++++---- lib/procinfo_unix.cpp | 10 +++++++--- 11 files changed, 52 insertions(+), 27 deletions(-) mode change 100755 => 100644 client/gpu_detect.cpp diff --git a/api/graphics2_unix.cpp b/api/graphics2_unix.cpp index d777789ec3..63f6c77720 100644 --- a/api/graphics2_unix.cpp +++ b/api/graphics2_unix.cpp @@ -191,8 +191,11 @@ static void boinc_glut_init(int *argc, char** argv) { FILE *f = boinc_fopen("gfx_info", "r"); if (f) { // ToDo: change this to XML parsing - fscanf(f, "%d %d %d %d\n", &xpos, &ypos, &width, &height); + int n = fscanf(f, "%d %d %d %d\n", &xpos, &ypos, &width, &height); fclose(f); + if (n != 4) { + fprintf(stderr, "failed to parse gfx_info"); + } } glutInit (argc, argv); diff --git a/client/app_control.cpp b/client/app_control.cpp index cf97ee6260..bb532d27c4 100644 --- a/client/app_control.cpp +++ b/client/app_control.cpp @@ -595,8 +595,8 @@ bool ACTIVE_TASK::temporary_exit_file_present(double& x, char* buf) { } else { x = y; } - fgets(buf, 256, f); // read the \n - fgets(buf, 256, f); + (void) fgets(buf, 256, f); // read the \n + (void) fgets(buf, 256, f); strip_whitespace(buf); fclose(f); return true; @@ -1446,7 +1446,7 @@ void ACTIVE_TASK::read_task_state_file() { FILE* f = fopen(path, "r"); if (!f) return; buf[0] = 0; - fread(buf, 1, 4096, f); + (void) fread(buf, 1, 4096, f); fclose(f); buf[4095] = 0; double x; diff --git a/client/app_start.cpp b/client/app_start.cpp index afb29f9c19..a0f84f25f2 100644 --- a/client/app_start.cpp +++ b/client/app_start.cpp @@ -858,7 +858,10 @@ int ACTIVE_TASK::start(bool test) { char* argv[100]; char current_dir[1024]; - getcwd(current_dir, sizeof(current_dir)); + if (getcwd(current_dir, sizeof(current_dir)) == NULL) { + sprintf(buf, "Can't get cwd"); + goto error; + } sprintf(cmdline, "%s %s", wup->command_line.c_str(), app_version->cmdline @@ -1005,7 +1008,7 @@ int ACTIVE_TASK::start(bool test) { // hook up stderr to a specially-named file // - freopen(STDERR_FILE, "a", stderr); + (void) freopen(STDERR_FILE, "a", stderr); if (!config.no_priority_change) { #if HAVE_SETPRIORITY diff --git a/client/cs_platforms.cpp b/client/cs_platforms.cpp index 08986c87ab..fd1545d3a2 100644 --- a/client/cs_platforms.cpp +++ b/client/cs_platforms.cpp @@ -142,7 +142,7 @@ void CLIENT_STATE::detect_platforms() { strlcat(cmdline," -m",256); if ((f=popen(cmdline,"r"))) { while (!std::feof(f)) { - fgets(cmdline,256,f); + if (!fgets(cmdline,256,f)) break; if (strstr(cmdline,"x86_64")) support64=1; } pclose(f); @@ -191,7 +191,7 @@ void CLIENT_STATE::detect_platforms() { f = popen(cmdline, "r"); if (f) { while (!std::feof(f)) { - fgets(cmdline,256,f); + if (!fgets(cmdline,256,f)) break; // If the library is 32-bit ELF, then we're // golden. if (strstr(cmdline, "ELF") && strstr(cmdline, "32-bit")) support32=1; diff --git a/client/gpu_detect.cpp b/client/gpu_detect.cpp old mode 100755 new mode 100644 diff --git a/client/hostinfo_unix.cpp b/client/hostinfo_unix.cpp index 1f0d61f7de..d6745e9f6f 100644 --- a/client/hostinfo_unix.cpp +++ b/client/hostinfo_unix.cpp @@ -1244,11 +1244,12 @@ int HOST_INFO::get_virtualbox_version() { #endif fd = popen(cmd, "r"); if (fd) { - fgets(virtualbox_version, sizeof(virtualbox_version), fd); - newlinePtr = strchr(virtualbox_version, '\n'); - if (newlinePtr) *newlinePtr = '\0'; - newlinePtr = strchr(virtualbox_version, '\r'); - if (newlinePtr) *newlinePtr = '\0'; + if (fgets(virtualbox_version, sizeof(virtualbox_version), fd)) { + newlinePtr = strchr(virtualbox_version, '\n'); + if (newlinePtr) *newlinePtr = '\0'; + newlinePtr = strchr(virtualbox_version, '\r'); + if (newlinePtr) *newlinePtr = '\0'; + } pclose(fd); } } diff --git a/client/log_flags.cpp b/client/log_flags.cpp index 6bf17625ec..d7e23ccb01 100644 --- a/client/log_flags.cpp +++ b/client/log_flags.cpp @@ -519,7 +519,12 @@ int read_config_file(bool init, const char* fname) { #ifdef _WIN32 _chdir(config.data_dir); #else - chdir(config.data_dir); + if (chdir(config.data_dir)) { + msg_printf(NULL, MSG_INFO, + "Couldn't change to config.data_dir" + ); + return ERR_OPENDIR; + } #endif } } else { diff --git a/client/switcher.cpp b/client/switcher.cpp index 157c55ab20..7bc1aa84f0 100644 --- a/client/switcher.cpp +++ b/client/switcher.cpp @@ -67,19 +67,25 @@ int main(int /*argc*/, char** argv) { pw = getpwuid(getuid()); if (pw) strcpy(user_name, pw->pw_name); grp = getgrgid(getgid()); - if (grp) strcpy(group_name, grp->gr_gid); + if (grp) { + strcpy(group_name, grp->gr_gid); + } #endif // We are running setuid root, so setgid() sets real group ID, // effective group ID and saved set_group-ID for this process grp = getgrnam(group_name); - if (grp) setgid(grp->gr_gid); + if (grp) { + (void) setgid(grp->gr_gid); + } // We are running setuid root, so setuid() sets real user ID, // effective user ID and saved set_user-ID for this process pw = getpwnam(user_name); - if (pw) setuid(pw->pw_uid); + if (pw) { + (void) setuid(pw->pw_uid); + } // For unknown reasons, the LD_LIBRARY_PATH and DYLD_LIBRARY_PATH // environment variables are not passed in to switcher, though all diff --git a/lib/crypt.cpp b/lib/crypt.cpp index b34f4d7d3d..d1a0e1b20c 100644 --- a/lib/crypt.cpp +++ b/lib/crypt.cpp @@ -208,14 +208,17 @@ int scan_key_hex(FILE* f, KEY* key, int size) { } if (j != len) return ERR_NULL; #else - fscanf(f, "%d", &num_bits); + int fs = fscanf(f, "%d", &num_bits); + if (fs != 1) return ERR_NULL; key->bits = num_bits; len = size - sizeof(key->bits); for (i=0; idata[i] = n; } - fscanf(f, "."); + fs = fscanf(f, "."); + if (fs == EOF) return ERR_NULL; #endif return 0; } diff --git a/lib/diagnostics.cpp b/lib/diagnostics.cpp index 2f691fd563..c00a6704e8 100644 --- a/lib/diagnostics.cpp +++ b/lib/diagnostics.cpp @@ -608,7 +608,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. - write(fileno(stderr),"Stack trace (",strlen("Stack trace (")); + (void) write(fileno(stderr),"Stack trace (",strlen("Stack trace (")); char mbuf[10]; char *p=mbuf+9; int i=size; @@ -617,10 +617,10 @@ void boinc_catch_signal(int signal) { *(p--)=i%10+'0'; i/=10; } - write(fileno(stderr),p+1,strlen(p+1)); - write(fileno(stderr)," frames):",strlen(" frames):")); + (void) write(fileno(stderr),p+1,strlen(p+1)); + (void) write(fileno(stderr)," frames):",strlen(" frames):")); mbuf[0]=10; - write(fileno(stderr),mbuf,1); + (void) write(fileno(stderr),mbuf,1); backtrace_symbols_fd(array, size, fileno(stderr)); #endif diff --git a/lib/procinfo_unix.cpp b/lib/procinfo_unix.cpp index d848e8487b..cc1e283709 100644 --- a/lib/procinfo_unix.cpp +++ b/lib/procinfo_unix.cpp @@ -47,9 +47,10 @@ #include // definitions for solaris /proc structs #endif +#include "error_numbers.h" +#include "filesys.h" #include "str_util.h" #include "str_replace.h" -#include "filesys.h" #include "procinfo.h" @@ -219,8 +220,11 @@ int procinfo_setup(PROC_MAP& pm) { sprintf(pidpath, "/proc/%s/stat", piddir->d_name); fd = fopen(pidpath, "r"); if (fd) { - fgets(buf, sizeof(buf), fd); - retval = ps.parse(buf); + if (fgets(buf, sizeof(buf), fd) == NULL) { + retval = ERR_NULL; + } else { + retval = ps.parse(buf); + } fclose(fd); if (retval) {