Author: eadler
Date: Wed Jun 13 00:45:38 2018
New Revision: 335024
URL: https://svnweb.freebsd.org/changeset/base/335024

Log:
  top(1): several small bugfixes and nits
  
  - initialize all maybe uninitialized vars with bogus values. This shuts
  up the compiler, and causes crashes if it changes later.
  - mark noreturn as noreturn
  - removed unused macro
  - handle x_procstate as runtime rather than pre-processor
  - avoid using void functions in condtionals
  
  Tested with clang, gcc 7, gcc 9

Modified:
  head/usr.bin/top/Makefile
  head/usr.bin/top/display.c
  head/usr.bin/top/machine.c
  head/usr.bin/top/top.c

Modified: head/usr.bin/top/Makefile
==============================================================================
--- head/usr.bin/top/Makefile   Wed Jun 13 00:45:35 2018        (r335023)
+++ head/usr.bin/top/Makefile   Wed Jun 13 00:45:38 2018        (r335024)
@@ -9,8 +9,7 @@ MAN=    top.1
 
 .if ${COMPILER_TYPE} == "gcc"
 .if ${COMPILER_VERSION} >= 50000
-CFLAGS.gcc=-Wno-error=cast-qual -Wno-error=discarded-qualifiers 
-Wno-error=incompatible-pointer-types \
-       -Wno-error=maybe-uninitialized
+CFLAGS.gcc=-Wno-error=cast-qual -Wno-error=discarded-qualifiers 
-Wno-error=incompatible-pointer-types
 .else #base gcc
 NO_WERROR=
 .endif

Modified: head/usr.bin/top/display.c
==============================================================================
--- head/usr.bin/top/display.c  Wed Jun 13 00:45:35 2018        (r335023)
+++ head/usr.bin/top/display.c  Wed Jun 13 00:45:38 2018        (r335024)
@@ -377,12 +377,13 @@ u_procstates(int total, int *brkdn)
     if (ltotal != total)
     {
        /* move and overwrite */
-#if (x_procstate == 0)
+if (x_procstate == 0) {
        Move_to(x_procstate, y_procstate);
-#else
+}
+else {
        /* cursor is already there...no motion needed */
-       /* assert(lastline == 1); */
-#endif
+       assert(lastline == 1);
+}
        printf("%d", total);
 
        /* if number of digits differs, rewrite the label */
@@ -955,11 +956,14 @@ new_message(int type, const char *msgfmt, ...)
            i = strlen(next_msg);
            if ((type & MT_delayed) == 0)
            {
-               type & MT_standout ? top_standout(next_msg) :
-                                    fputs(next_msg, stdout);
-               (void) clear_eol(msglen - i);
-               msglen = i;
-               next_msg[0] = '\0';
+                       if (type & MT_standout) {
+                               top_standout(next_msg);
+                       } else {
+                               fputs(next_msg, stdout);
+                       }
+                       clear_eol(msglen - i);
+                       msglen = i;
+                       next_msg[0] = '\0';
            }
        }
     }
@@ -967,7 +971,11 @@ new_message(int type, const char *msgfmt, ...)
     {
        if ((type & MT_delayed) == 0)
        {
-           type & MT_standout ? top_standout(next_msg) : fputs(next_msg, 
stdout);
+               if (type & MT_standout) {
+                       top_standout(next_msg);
+               } else {
+                       fputs(next_msg, stdout);
+               }
            msglen = strlen(next_msg);
            next_msg[0] = '\0';
        }

Modified: head/usr.bin/top/machine.c
==============================================================================
--- head/usr.bin/top/machine.c  Wed Jun 13 00:45:35 2018        (r335023)
+++ head/usr.bin/top/machine.c  Wed Jun 13 00:45:38 2018        (r335024)
@@ -79,8 +79,6 @@ struct handle {
 #define PROCSIZE(pp) ((pp)->ki_size / 1024)
 
 #define RU(pp) (&(pp)->ki_rusage)
-#define RUTOT(pp) \
-       (RU(pp)->ru_inblock + RU(pp)->ru_oublock + RU(pp)->ru_majflt)
 
 #define        PCTCPU(pp) (pcpu[pp - pbase])
 

Modified: head/usr.bin/top/top.c
==============================================================================
--- head/usr.bin/top/top.c      Wed Jun 13 00:45:35 2018        (r335023)
+++ head/usr.bin/top/top.c      Wed Jun 13 00:45:38 2018        (r335024)
@@ -245,8 +245,8 @@ main(int argc, char *argv[])
     char *env_top;
     const char **preset_argv;
     int  preset_argc = 0;
-    const char **av;
-    int  ac;
+    const char **av = NULL;
+    int  ac = -1;
     bool dostates = false;
     bool do_unames = true;
     char interactive = 2;
@@ -1230,7 +1230,7 @@ top_winch(int i __unused)         /* SIGWINCH handler */
     winchflag = 1;
 }
 
-void
+void __dead2
 quit(int status)               /* exit under duress */
 {
     end_screen();
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to