From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12354 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: alternative form flag with zero octal value Date: Wed, 10 Jan 2018 21:17:50 -0500 Message-ID: <20180111021750.GH1627@brightrain.aerifal.cx> References: <20180111114305.GG1268@lucy.localdomain> <20180111020246.GG1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="pFpMklMRdxwSC3Yi" X-Trace: blaine.gmane.org 1515636970 13450 195.159.176.226 (11 Jan 2018 02:16:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 11 Jan 2018 02:16:10 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) Cc: musl@lists.openwall.com To: Peter Wang Original-X-From: musl-return-12370-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jan 11 03:16:06 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 1eZSPV-00038U-1D for gllmg-musl@m.gmane.org; Thu, 11 Jan 2018 03:16:05 +0100 Original-Received: (qmail 26147 invoked by uid 550); 11 Jan 2018 02:18:06 -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 26123 invoked from network); 11 Jan 2018 02:18:05 -0000 Content-Disposition: inline In-Reply-To: <20180111020246.GG1627@brightrain.aerifal.cx> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12354 Archived-At: --pFpMklMRdxwSC3Yi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Jan 10, 2018 at 09:02:46PM -0500, Rich Felker wrote: > On Thu, Jan 11, 2018 at 11:43:05AM +1100, Peter Wang wrote: > > Hi, > > > > I'm not certain it is a bug, but this program produces "00" instead of "0": > > > > #include > > int main(void) > > { > > printf("%#o\n", 0); > > return 0; > > } > > > > Please Cc: any replies as I am not subscribed to this list. > > Indeed, this is a bug. I'm not sure whether it was introduced in > commit 78897b0dc00b7cd5c29af5e0b7eebf2396d8dce0 or already present, > but it was not present in Dmitry Levin's original more complex version > of the patch. I'm going to essentially revert this commit and replace > it with an alternate one-line fix using infrastructure that wasn't > available at the time but added later in commit > 167dfe9672c116b315e72e57a55c7769f180dffa. > > Thanks for the report. Here's the patch I'm going to push if I don't find any problems with it. Rich --pFpMklMRdxwSC3Yi Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-fix-printf-alt-form-octal-with-value-0-and-no-explic.patch" >From b64539ae06aa91a407359238f4e909adb9bfab3d Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 10 Jan 2018 20:45:02 -0500 Subject: [PATCH] fix printf alt-form octal with value 0 and no explicit precision commit 78897b0dc00b7cd5c29af5e0b7eebf2396d8dce0 wrongly simplified Dmitry Levin's original submitted patch fixing alt-form octal with the zero flag and field width present, omitting the special case where the value is zero. as a result, printf("%#o",0) wrongly prints "00" rather than "0". the logic prior to this commit was actually better, in that it was aligned with how the alt-form flag (#) for printf is specified ("it shall increase the precision"). at the time there was no good way to avoid the zero flag issue with the old logic, but commit 167dfe9672c116b315e72e57a55c7769f180dffa added tracking of whether an explicit precision was provided. revert commit 78897b0dc00b7cd5c29af5e0b7eebf2396d8dce0 and switch to using the explicit precision indicator for suppressing the zero flag. --- src/stdio/vfprintf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c index 15356f5..50fb55c 100644 --- a/src/stdio/vfprintf.c +++ b/src/stdio/vfprintf.c @@ -559,7 +559,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, if (0) { case 'o': a = fmt_o(arg.i, z); - if ((fl&ALT_FORM) && p=0) fl &= ~ZERO_PAD; + if (xp) fl &= ~ZERO_PAD; if (!arg.i && !p) { a=z; break; -- 2.10.0 --pFpMklMRdxwSC3Yi--