]> granicus.if.org Git - procps-ng/commitdiff
top: correct, improve and otherwise tweak configs_read
authorJim Warner <james.warner@comcast.net>
Tue, 20 Aug 2013 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Fri, 30 Aug 2013 12:08:25 +0000 (22:08 +1000)
This patch addresses the four '-Wunused-result' errors
generated whenever an optimized compile is invoked. It
also made the configs_read() guy a little more robust.

In the process, some logic was rearranged slightly and
some comments were re-indented simply for consistency.

Reference(s):
warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result]
warning: ignoring return value of 'fscanf', declared with attribute warn_unused_result [-Wunused-result]

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c

index c29bb07c863f54208567f77f65cdfdd340675944..bdfcf20af491d7e2d667380ba094adc36ee64fb1 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -3394,26 +3394,25 @@ static void configs_read (void) {
 
    fp = fopen(SYS_RCFILESPEC, "r");
    if (fp) {
-      fbuf[0] = '\0';
-      fgets(fbuf, sizeof(fbuf), fp);             // sys rc file, line 1
-      if (strchr(fbuf, 's')) Secure_mode = 1;
-      fbuf[0] = '\0';
-      fgets(fbuf, sizeof(fbuf), fp);             // sys rc file, line 2
-      sscanf(fbuf, "%f", &Rc.delay_time);
+      if (fgets(fbuf, sizeof(fbuf), fp)) {     // sys rc file, line 1
+         Secure_mode = 1;
+         if (fgets(fbuf, sizeof(fbuf), fp))    // sys rc file, line 2
+            sscanf(fbuf, "%f", &Rc.delay_time);
+      }
       fclose(fp);
    }
 
    fp = fopen(Rc_name, "r");
    if (fp) {
       int tmp_whole, tmp_fract;
-      fbuf[0] = '\0';
-      fgets(fbuf, sizeof(fbuf), fp);             // ignore eyecatcher
+      if (fgets(fbuf, sizeof(fbuf), fp))       // ignore eyecatcher
+         ;                                     // avoid -Wunused-result
       if (6 != fscanf(fp
          , "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%d.%d, Curwin=%d\n"
          , &Rc.id, &Rc.mode_altscr, &Rc.mode_irixps, &tmp_whole, &tmp_fract, &i)) {
             p = fmtmk(N_fmt(RC_bad_files_fmt), Rc_name);
             Rc_questions = -1;
-            goto try_inspect_entries;            // maybe a faulty 'inspect' echo
+            goto try_inspect_entries;          // maybe a faulty 'inspect' echo
       }
       // you saw that, right?  (fscanf stickin' it to 'i')
       Curwin = &Winstk[i];
@@ -3442,20 +3441,20 @@ static void configs_read (void) {
                goto default_or_error;
 
          switch (Rc.id) {
-            case 'f':                  // 3.3.0 thru 3.3.3 (procps-ng)
-               SETw(w, Show_JRNUMS);   //    fall through !
-            case 'g':                  // current RCF_VERSION_ID
-            default:                   // and future versions?
+            case 'a':                          // 3.2.8 (former procps)
+               if (config_cvt(w))
+                  goto default_or_error;
+               break;
+            case 'f':                          // 3.3.0 thru 3.3.3 (procps-ng)
+               SETw(w, Show_JRNUMS);           //    fall through !
+            case 'g':                          // current RCF_VERSION_ID
+            default:                           // and future versions?
                if (strlen(w->rc.fieldscur) != sizeof(DEF_FIELDS) - 1)
                   goto default_or_error;
                for (x = 0; x < P_MAXPFLGS; ++x)
                   if (P_MAXPFLGS <= FLDget(w, x))
                      goto default_or_error;
                break;
-            case 'a':                  // 3.2.8 (former procps)
-               if (config_cvt(w))
-                  goto default_or_error;
-               break;
          }
 #ifndef USE_X_COLHDR
          OFFw(w, NOHIFND_xxx | NOHISEL_xxx);
@@ -3463,8 +3462,9 @@ static void configs_read (void) {
       } // end: for (GROUPSMAX)
 
       // any new addition(s) last, for older rcfiles compatibility...
-      fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n"
-         , &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale, &Rc.zero_suppress);
+      if (fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n"
+         , &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale, &Rc.zero_suppress))
+            ;                                  // avoid -Wunused-result
 
 try_inspect_entries:
       // we'll start off Inspect stuff with 1 'potential' blank line