From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10478 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] fix printf regression with alt-form octal, default precision Date: Fri, 16 Sep 2016 17:58:41 -0400 Message-ID: <20160916215841.GP15995@brightrain.aerifal.cx> References: <20160804010740.GA12707@altlinux.org> <20160915163757.GK15995@brightrain.aerifal.cx> <20160915181456.GA19794@altlinux.org> 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 1474063141 22871 195.159.176.226 (16 Sep 2016 21:59:01 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 16 Sep 2016 21:59:01 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-10491-gllmg-musl=m.gmane.org@lists.openwall.com Fri Sep 16 23:58:57 2016 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 1bl19r-0005Fu-0P for gllmg-musl@m.gmane.org; Fri, 16 Sep 2016 23:58:55 +0200 Original-Received: (qmail 1608 invoked by uid 550); 16 Sep 2016 21:58:54 -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 1590 invoked from network); 16 Sep 2016 21:58:54 -0000 Content-Disposition: inline In-Reply-To: <20160915181456.GA19794@altlinux.org> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:10478 Archived-At: On Thu, Sep 15, 2016 at 09:14:56PM +0300, Dmitry V. Levin wrote: > On Thu, Sep 15, 2016 at 12:37:57PM -0400, Rich Felker wrote: > > On Thu, Aug 04, 2016 at 04:07:40AM +0300, Dmitry V. Levin wrote: > > > commit v1.1.5-10-gb91cdbe2bc8b626aa04dc6e3e84345accf34e4b1 that fixed > > > behavior of printf with alt-form octal, zero precision, zero value, > > > at the same time broke alt-form octal with default precision, > > > e. g. printf("%#09o", 1). > > > --- > > > src/stdio/vfprintf.c | 9 ++++++++- > > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > > > diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c > > > index 2ecf769..ac2891c 100644 > > > --- a/src/stdio/vfprintf.c > > > +++ b/src/stdio/vfprintf.c > > > @@ -570,7 +570,14 @@ 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 > > + if (fl&ALT_FORM) { > > > + if (p >= 0 && p > > + p=z-a+1; > > > + } else if (arg.i) { > > > + prefix+=5; > > > + pl=1; > > > + } > > > + } > > > } if (0) { > > > case 'd': case 'i': > > > pl=1; > > > > I think the attached simpler patch should work just as well. Adjusting > > 'p' to implement '#' was probably a bad idea since it makes the later > > code paths think an explicit precision was specified when it was not. > > "Add a prefix of '0' when p is too short to have a leading '0' > > already" seems like safer logic. > > > > I'm also attaching some test cases I ran. > > > > Rich > > > > diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c > > index 2ecf769..e439a07 100644 > > --- a/src/stdio/vfprintf.c > > +++ b/src/stdio/vfprintf.c > > @@ -570,7 +570,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 > + if ((fl&ALT_FORM) && p > } if (0) { > > case 'd': case 'i': > > pl=1; > > Yes, this also works, thanks. OK, I'm committing this version. Thanks! Rich