mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] handle whitespace before %% in scanf
@ 2017-07-09 21:00 Bartosz Brachaczek
  2017-07-10  2:00 ` Rich Felker
  2017-07-11  1:20 ` Rich Felker
  0 siblings, 2 replies; 10+ messages in thread
From: Bartosz Brachaczek @ 2017-07-09 21:00 UTC (permalink / raw)
  To: musl; +Cc: Bartosz Brachaczek

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;
 		}
 
diff --git a/src/stdio/vfwscanf.c b/src/stdio/vfwscanf.c
index ad8e2b9a..5d387a2d 100644
--- a/src/stdio/vfwscanf.c
+++ b/src/stdio/vfwscanf.c
@@ -117,8 +117,12 @@ int vfwscanf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap)
 			continue;
 		}
 		if (*p != '%' || p[1] == '%') {
-			p += *p=='%';
-			c = getwc(f);
+			if (*p == '%') {
+				p++;
+				while (iswspace((c=getwc(f)))) pos++;
+			} else {
+				c = getwc(f);
+			}
 			if (c!=*p) {
 				ungetwc(c, f);
 				if (c<0) goto input_fail;
-- 
2.13.0



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-09-04 22:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-09 21:00 [PATCH] handle whitespace before %% in scanf Bartosz Brachaczek
2017-07-10  2:00 ` Rich Felker
2017-07-10  8:22   ` Bartosz Brachaczek
2017-07-10 14:44     ` Jens Gustedt
2017-07-10 20:59       ` Rich Felker
2017-09-04 22:00       ` Bartosz Brachaczek
2017-09-04 22:57         ` Jens Gustedt
2017-07-11  1:20 ` Rich Felker
2017-09-04 20:59   ` Rich Felker
2017-09-04 21:56     ` Bartosz Brachaczek

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).