svn commit: r335039 - head/usr.bin/top

Eitan Adler eadler at FreeBSD.org
Wed Jun 13 08:52:16 UTC 2018


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);
 }
 
 /*


More information about the svn-src-head mailing list