From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11902 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, 4 Sep 2017 16:59:33 -0400 Message-ID: <20170904205933.GN1627@brightrain.aerifal.cx> References: <20170709210018.16369-1-b.brachaczek@gmail.com> <20170711012039.GO1627@brightrain.aerifal.cx> 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 1504558805 17539 195.159.176.226 (4 Sep 2017 21:00:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 4 Sep 2017 21:00:05 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11915-gllmg-musl=m.gmane.org@lists.openwall.com Mon Sep 04 22:59:51 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 1doyTA-0003aC-3M for gllmg-musl@m.gmane.org; Mon, 04 Sep 2017 22:59:44 +0200 Original-Received: (qmail 9423 invoked by uid 550); 4 Sep 2017 20:59:47 -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 9399 invoked from network); 4 Sep 2017 20:59:46 -0000 Content-Disposition: inline In-Reply-To: <20170711012039.GO1627@brightrain.aerifal.cx> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11902 Archived-At: On Mon, Jul 10, 2017 at 09:20:39PM -0400, Rich Felker wrote: > 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. I tried going forward with the idea I proposed, but it looks like it's actually more invasive: in addition to adding the final case to actually handle '%', it adds a new case where a conversion specifier does not consume a variadic input, and a new case where width is forced to 1 and modifier flags and explicit widths are rejected. As such I think your patch as originally submitted is probably the best approach. Sorry for the delay in reviewing and accepting it. Rich