Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Jun 2018 05:05:21 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r334941 - head/usr.bin/top
Message-ID:  <201806110505.w5B55LjF002125@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Mon Jun 11 05:05:20 2018
New Revision: 334941
URL: https://svnweb.freebsd.org/changeset/base/334941

Log:
  top(1): handle 0 in "digits" functions

Modified:
  head/usr.bin/top/Makefile
  head/usr.bin/top/utils.c

Modified: head/usr.bin/top/Makefile
==============================================================================
--- head/usr.bin/top/Makefile	Mon Jun 11 02:09:20 2018	(r334940)
+++ head/usr.bin/top/Makefile	Mon Jun 11 05:05:20 2018	(r334941)
@@ -5,7 +5,6 @@
 PROG=	top
 SRCS=	commands.c display.c machine.c screen.c top.c \
 	username.c utils.c
-CFLAGS+= -I ${.OBJDIR}
 MAN=	top.1
 
 .if ${COMPILER_TYPE} == "gcc"

Modified: head/usr.bin/top/utils.c
==============================================================================
--- head/usr.bin/top/utils.c	Mon Jun 11 02:09:20 2018	(r334940)
+++ head/usr.bin/top/utils.c	Mon Jun 11 05:05:20 2018	(r334941)
@@ -124,16 +124,18 @@ itoa7(int val)
 
 /*
  *  digits(val) - return number of decimal digits in val.  Only works for
- *	positive numbers.  If val <= 0 then digits(val) == 0.
+ *	non-negative numbers.  If val <= 0 then digits(val) == 0.
  */
 
-int
+int __pure2
 digits(int val)
 {
     int cnt = 0;
+	if (val == 0) {
+		return 1;
+	}
 
-    while (val > 0)
-    {
+    while (val > 0) {
 		cnt++;
 		val /= 10;
     }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806110505.w5B55LjF002125>