Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Jun 2018 08:52:12 +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: r335039 - head/usr.bin/top
Message-ID:  <201806130852.w5D8qC6R093668@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Wed Jun 13 08:52:12 2018
New Revision: 335039
URL: https://svnweb.freebsd.org/changeset/base/335039

Log:
  top(1): replace homegrown itoa with sprintf
  
  Much of this should be inlined to the callsite, but leave it here for
  now to make it easier to make it easier bisect later.

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

Modified: head/usr.bin/top/utils.c
==============================================================================
--- head/usr.bin/top/utils.c	Wed Jun 13 08:52:09 2018	(r335038)
+++ head/usr.bin/top/utils.c	Wed Jun 13 08:52:12 2018	(r335039)
@@ -70,24 +70,13 @@ _Static_assert(sizeof(int) <= 4, "buffer too small for
 char *
 itoa(unsigned int val)
 {
-    char *ptr;
     static char buffer[16];	/* result is built here */
     				/* 16 is sufficient since the largest number
 				   we will ever convert will be 2^32-1,
 				   which is 10 digits. */
 
-    ptr = buffer + sizeof(buffer);
-    *--ptr = '\0';
-    if (val == 0)
-    {
-	*--ptr = '0';
-    }
-    else while (val != 0)
-    {
-	*--ptr = (val % 10) + '0';
-	val /= 10;
-    }
-    return(ptr);
+	sprintf(buffer, "%u", val);
+    return (buffer);
 }
 
 /*
@@ -99,28 +88,13 @@ itoa(unsigned int val)
 char *
 itoa7(int val)
 {
-    char *ptr;
     static char buffer[16];	/* result is built here */
     				/* 16 is sufficient since the largest number
 				   we will ever convert will be 2^32-1,
 				   which is 10 digits. */
 
-    ptr = buffer + sizeof(buffer);
-    *--ptr = '\0';
-    if (val == 0)
-    {
-	*--ptr = '0';
-    }
-    else while (val != 0)
-    {
-	*--ptr = (val % 10) + '0';
-	val /= 10;
-    }
-    while (ptr > buffer + sizeof(buffer) - 7)
-    {
-	*--ptr = ' ';
-    }
-    return(ptr);
+	sprintf(buffer, "%6u", val);
+    return (buffer);
 }
 
 /*



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