diff --git a/api/graphics2_unix.cpp b/api/graphics2_unix.cpp
index d777789ec3afd796035d0c009594ef5f05969008..63f6c77720236c737f32b070024f1725fe65c3c6 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 cf97ee62606a1a09c46272c9b29893ca84712e6a..bb532d27c456076a118433b3a5f965a685af3a74 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 afb29f9c193e880fec705f544ee0a79503c9d0d8..a0f84f25f2cb9900c70daa88932c03eff7729089 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 08986c87abf57393eb1c08e3e4ff8d9c5ba479db..fd1545d3a2d9ca6a3b86b34cf633faac8a9ff464 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 1f0d61f7de116a68a6422aa3bed6bbfc06cfceb0..d6745e9f6fd33b7109e4fedacdf0eb96c2bbb085 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 6bf17625ecda695f84f541831f8e08cff261428d..d7e23ccb01673d7916810ec437564966c41a8c3f 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 157c55ab20979d3bbeaa45ef478cb5af7fe22486..7bc1aa84f0dd1f3d19cb9bb19baf7330731fae7e 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 b34f4d7d3d657e2f7d4944d505df846b6c743122..d1a0e1b20c82e9b553b23acf62ea8d198e04e3af 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; i<len; i++) {
-        fscanf(f, "%2x", &n);
+        fs = fscanf(f, "%2x", &n);
+        if (fs != 1) return ERR_NULL;
         key->data[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 2f691fd5632f91f344cb33b5d3108bc3213fa36a..c00a6704e801c884c13bf7f90df5afe5cca2163a 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 d848e8487bbc49f8631f981a0eef5b1ed335519d..cc1e28370903e187e77824a3d9fab46c77654f4d 100644
--- a/lib/procinfo_unix.cpp
+++ b/lib/procinfo_unix.cpp
@@ -47,9 +47,10 @@
 #include <procfs.h>  // 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) {