From owner-svn-src-head@freebsd.org Wed Jun 13 00:45:40 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8C4FC1010A6D; Wed, 13 Jun 2018 00:45:40 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 04C80827A8; Wed, 13 Jun 2018 00:45:40 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D00171236D; Wed, 13 Jun 2018 00:45:39 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5D0jdtd043670; Wed, 13 Jun 2018 00:45:39 GMT (envelope-from eadler@FreeBSD.org) Received: (from eadler@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5D0jdO1043666; Wed, 13 Jun 2018 00:45:39 GMT (envelope-from eadler@FreeBSD.org) Message-Id: <201806130045.w5D0jdO1043666@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eadler set sender to eadler@FreeBSD.org using -f From: Eitan Adler Date: Wed, 13 Jun 2018 00:45:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335024 - head/usr.bin/top X-SVN-Group: head X-SVN-Commit-Author: eadler X-SVN-Commit-Paths: head/usr.bin/top X-SVN-Commit-Revision: 335024 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jun 2018 00:45:40 -0000 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();