From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13166 Path: news.gmane.org!.POSTED!not-for-mail From: Alexander Monakov Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] simplify __procfdname by folding the 0 case Date: Sun, 2 Sep 2018 14:14:52 +0300 (MSK) Message-ID: References: <5b8b9a8b.1c69fb81.ed159.bb37@mx.google.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Trace: blaine.gmane.org 1535886785 9519 195.159.176.226 (2 Sep 2018 11:13:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Sep 2018 11:13:05 +0000 (UTC) User-Agent: Alpine 2.20.13 (LNX 116 2015-12-14) To: musl@lists.openwall.com Original-X-From: musl-return-13182-gllmg-musl=m.gmane.org@lists.openwall.com Sun Sep 02 13:13:01 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1fwQJQ-0002Ns-U9 for gllmg-musl@m.gmane.org; Sun, 02 Sep 2018 13:13:01 +0200 Original-Received: (qmail 32582 invoked by uid 550); 2 Sep 2018 11:15:05 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 32554 invoked from network); 2 Sep 2018 11:15:03 -0000 In-Reply-To: <5b8b9a8b.1c69fb81.ed159.bb37@mx.google.com> Xref: news.gmane.org gmane.linux.lib.musl.general:13166 Archived-At: In 2016 I sent a more comprehensive cleanup, please review the thread starting at http://openwall.com/lists/musl/2016/02/21/2 Some notes on the patch below. On Sun, 2 Sep 2018, Fangrui Song wrote: > --- a/src/internal/procfdname.c > +++ b/src/internal/procfdname.c > @@ -2,12 +2,7 @@ void __procfdname(char *buf, unsigned fd) > { > unsigned i, j; > for (i=0; (buf[i] = "/proc/self/fd/"[i]); i++); > - if (!fd) { > - buf[i] = '0'; > - buf[i+1] = 0; > - return; > - } > - for (j=fd; j; j/=10, i++); > - buf[i] = 0; > - for (; fd; fd/=10) buf[--i] = '0' + fd%10; > + for (j=fd; i++, j /= 10; ); This is not correct as it only increments i once. A do-while loop would do the job better here. > + buf[i] = '\0'; > + while (buf[--i] = '0' + fd%10, fd /= 10); Likewise, a do-while loop would be more suitable here. > } Alexander