From owner-svn-src-head@freebsd.org Wed Jun 13 08:52:15 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 DE8CF1015107; Wed, 13 Jun 2018 08:52:15 +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 71F9C75324; Wed, 13 Jun 2018 08:52:13 +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 E156E172D4; Wed, 13 Jun 2018 08:52:12 +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 w5D8qCHC093669; Wed, 13 Jun 2018 08:52:12 GMT (envelope-from eadler@FreeBSD.org) Received: (from eadler@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5D8qC6R093668; Wed, 13 Jun 2018 08:52:12 GMT (envelope-from eadler@FreeBSD.org) Message-Id: <201806130852.w5D8qC6R093668@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 08:52:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335039 - 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: 335039 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 08:52:16 -0000 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); } /*