From owner-svn-src-head@freebsd.org Sun Jun 3 02:58:55 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 EEF8FFE7D63; Sun, 3 Jun 2018 02:58:54 +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 9E92C693CB; Sun, 3 Jun 2018 02:58:54 +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 66CCD18BDE; Sun, 3 Jun 2018 02:58:54 +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 w532ws3q070243; Sun, 3 Jun 2018 02:58:54 GMT (envelope-from eadler@FreeBSD.org) Received: (from eadler@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w532wrss070240; Sun, 3 Jun 2018 02:58:53 GMT (envelope-from eadler@FreeBSD.org) Message-Id: <201806030258.w532wrss070240@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eadler set sender to eadler@FreeBSD.org using -f From: Eitan Adler Date: Sun, 3 Jun 2018 02:58:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334549 - 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: 334549 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: Sun, 03 Jun 2018 02:58:55 -0000 Author: eadler Date: Sun Jun 3 02:58:53 2018 New Revision: 334549 URL: https://svnweb.freebsd.org/changeset/base/334549 Log: top(1): misc minor improvements - use bool instead of int [0] - use calloc correctly [0] (this also caught an incorrect sizeof argument) [1] - use size_t over int [2] - correct style Reported by: pfg [0], scan-build [1], gcc [2] Modified: head/usr.bin/top/commands.c head/usr.bin/top/machine.c head/usr.bin/top/utils.c Modified: head/usr.bin/top/commands.c ============================================================================== --- head/usr.bin/top/commands.c Sun Jun 3 00:42:36 2018 (r334548) +++ head/usr.bin/top/commands.c Sun Jun 3 02:58:53 2018 (r334549) @@ -43,7 +43,7 @@ struct errs /* structure for a system-call error */ static char *err_string(void); static int str_adderr(char *str, int len, int err); -static int str_addarg(char *str, int len, char *arg, int first); +static int str_addarg(char *str, int len, char *arg, bool first); /* * show_help() - display the help screen; invoked in response to @@ -199,9 +199,9 @@ static char err_listem[] = char *err_string(void) { struct errs *errp; - int cnt = 0; - int first = true; - int currerr = -1; + int cnt = 0; + bool first = true; + int currerr = -1; int stringlen; /* characters still available in "string" */ static char string[STRMAX]; @@ -279,7 +279,7 @@ str_adderr(char *str, int len, int err) */ static int -str_addarg(char str[], int len, char arg[], int first) +str_addarg(char str[], int len, char arg[], bool first) { int arglen; Modified: head/usr.bin/top/machine.c ============================================================================== --- head/usr.bin/top/machine.c Sun Jun 3 00:42:36 2018 (r334548) +++ head/usr.bin/top/machine.c Sun Jun 3 02:58:53 2018 (r334549) @@ -381,8 +381,7 @@ machine_init(struct statics *statics) cpumask = 0; ncpus = 0; GETSYSCTL("kern.smp.maxcpus", maxcpu); - size = sizeof(long) * maxcpu * CPUSTATES; - times = calloc(size, 1); + times = calloc(maxcpu * CPUSTATES, sizeof(long)); if (times == NULL) err(1, "calloc %zu bytes", size); if (sysctlbyname("kern.cp_times", times, &size, NULL, 0) == -1) @@ -400,11 +399,10 @@ machine_init(struct statics *statics) ncpus++; } } - size = sizeof(long) * ncpus * CPUSTATES; - assert(size > 0); - pcpu_cp_old = calloc(1, size); - pcpu_cp_diff = calloc(1, size); - pcpu_cpu_states = calloc(1, size); + assert(ncpus > 0); + pcpu_cp_old = calloc(ncpus * CPUSTATES, sizeof(long)); + pcpu_cp_diff = calloc(ncpus * CPUSTATES, sizeof(long)); + pcpu_cpu_states = calloc(ncpus * CPUSTATES, sizeof(int)); statics->ncpus = ncpus; update_layout(); Modified: head/usr.bin/top/utils.c ============================================================================== --- head/usr.bin/top/utils.c Sun Jun 3 00:42:36 2018 (r334548) +++ head/usr.bin/top/utils.c Sun Jun 3 02:58:53 2018 (r334549) @@ -29,7 +29,7 @@ int atoiwi(const char *str) { - int len; + size_t len; len = strlen(str); if (len != 0)