[Pkg-wmaker-commits] [wmbubble] 180/207: Fix -Wunused-result compiler warnings.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Mon Aug 24 04:18:31 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository wmbubble.

commit 1dfe96aebb96b6ec3e5ae61a5ec4337fc918eed0
Author: Doug Torrance <dtorrance at monmouthcollege.edu>
Date:   Sat Nov 29 22:15:41 2014 -0600

    Fix -Wunused-result compiler warnings.
    
    In particular:
    bubblemon.c: In function ‘main’:
    bubblemon.c:447:6: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result [-Wunused-result]
          system(execute);
          ^
    sys_linux.c: In function ‘system_cpu’:
    sys_linux.c:38:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
      fscanf(stat, "%*s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64,
      ^
    sys_linux.c: In function ‘system_memory’:
    sys_linux.c:84:2: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
      fread(shit, 2048, 1, mem);
      ^
    sys_linux.c: In function ‘system_loadavg’:
    sys_linux.c:115:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
      fscanf(avg, "%d.%d %d.%d %d.%d", &bm.loadavg[0].i, &bm.loadavg[0].f,
      ^
---
 bubblemon.c |  5 ++++-
 sys_linux.c | 23 +++++++++++++++++------
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/bubblemon.c b/bubblemon.c
index f2fa542..3f9a66f 100644
--- a/bubblemon.c
+++ b/bubblemon.c
@@ -444,7 +444,10 @@ int main(int argc, char **argv) {
 				if (event.xbutton.button <= argc) {
 					snprintf(execute, 250, "%s &",
 					         argv[event.xbutton.button - 1]);
-					system(execute);
+					if (system(execute) == -1) {
+						fprintf(stderr, "execute failed\n");
+						exit(-1);
+					}
 				}
 				break;
 			case EnterNotify:
diff --git a/sys_linux.c b/sys_linux.c
index 41be9f1..7b34e09 100644
--- a/sys_linux.c
+++ b/sys_linux.c
@@ -35,8 +35,11 @@ int system_cpu(void) {
 	FILE *stat;
 
 	stat = fopen("/proc/stat", "r");
-	fscanf(stat, "%*s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64,
-	       &ab, &ac, &ad, &ae);
+	if (fscanf(stat, "%*s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64,
+		   &ab, &ac, &ad, &ae) == EOF) {
+		fprintf(stderr, "EOF when reading /proc/stat\n");
+		return -1;
+	}
 	fclose(stat);
 
 	/* Find out the CPU load */
@@ -81,7 +84,12 @@ void system_memory(void) {
 	 * sure beats opening the same file twice */
 	mem = fopen("/proc/meminfo", "r");
 	memset(shit, 0, sizeof(shit));
-	fread(shit, 2048, 1, mem);
+	if (fread(shit, 2048, 1, mem) < 2048) {
+		if (ferror(mem)) {
+			fprintf(stderr, "error reading /proc/meminfo\n");
+			return;
+		}
+	}
 	p = strstr(shit, "MemTotal");
 	if (p) {
 		sscanf(p, "MemTotal:%"PRIu64, &bm.mem_max);
@@ -112,8 +120,11 @@ void system_memory(void) {
 void system_loadavg(void) {
 	FILE *avg;
 	avg = fopen("/proc/loadavg", "r");
-	fscanf(avg, "%d.%d %d.%d %d.%d", &bm.loadavg[0].i, &bm.loadavg[0].f,
-	       &bm.loadavg[1].i, &bm.loadavg[1].f,
-	       &bm.loadavg[2].i, &bm.loadavg[2].f);
+	if (fscanf(avg, "%d.%d %d.%d %d.%d", &bm.loadavg[0].i, &bm.loadavg[0].f,
+		   &bm.loadavg[1].i, &bm.loadavg[1].f,
+		   &bm.loadavg[2].i, &bm.loadavg[2].f) == EOF) {
+		fprintf(stderr, "EOF when reading /proc/loadavg\n");
+		return;
+	}
 	fclose(avg);
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbubble.git



More information about the Pkg-wmaker-commits mailing list