From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11718 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] handle whitespace before %% in scanf Date: Mon, 10 Jul 2017 21:20:39 -0400 Message-ID: <20170711012039.GO1627@brightrain.aerifal.cx> References: <20170709210018.16369-1-b.brachaczek@gmail.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 1499736057 14237 195.159.176.226 (11 Jul 2017 01:20:57 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 11 Jul 2017 01:20:57 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11731-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jul 11 03:20:53 2017 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 1dUjr6-0003JH-LB for gllmg-musl@m.gmane.org; Tue, 11 Jul 2017 03:20:48 +0200 Original-Received: (qmail 13567 invoked by uid 550); 11 Jul 2017 01:20:51 -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 13543 invoked from network); 11 Jul 2017 01:20:51 -0000 Content-Disposition: inline In-Reply-To: <20170709210018.16369-1-b.brachaczek@gmail.com> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11718 Archived-At: On Sun, Jul 09, 2017 at 11:00:18PM +0200, Bartosz Brachaczek wrote: > this is mandated by C and POSIX standards and is in accordance with > glibc behavior. > --- > src/stdio/vfscanf.c | 10 +++++++--- > src/stdio/vfwscanf.c | 8 ++++++-- > 2 files changed, 13 insertions(+), 5 deletions(-) > > diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c > index d4d2454b..9e030fc4 100644 > --- a/src/stdio/vfscanf.c > +++ b/src/stdio/vfscanf.c > @@ -89,15 +89,19 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) > continue; > } > if (*p != '%' || p[1] == '%') { > - p += *p=='%'; > shlim(f, 0); > - c = shgetc(f); > + if (*p == '%') { > + p++; > + while (isspace((c=shgetc(f)))); > + } else { > + c = shgetc(f); > + } > if (c!=*p) { > shunget(f); > if (c<0) goto input_fail; > goto match_fail; > } > - pos++; > + pos += shcnt(f); > continue; > } Assuming your interpretation is correct, I have no objection to going forward with the change, but I don't think this is the right way to do it. The only reason %% was handled in the code that handles literal characters is because I assumed it behaves like one, but if it doesn't, it should just be handled as a format specifier that consumes space where it can use the existing code that does that, rather than complicting the code for literals and adding a duplicate of the space-skipping code to it. Rich