aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0064-handle-whitespace-before-in-scanf.patch
diff options
context:
space:
mode:
Diffstat (limited to 'main/musl/0064-handle-whitespace-before-in-scanf.patch')
-rw-r--r--main/musl/0064-handle-whitespace-before-in-scanf.patch61
1 files changed, 61 insertions, 0 deletions
diff --git a/main/musl/0064-handle-whitespace-before-in-scanf.patch b/main/musl/0064-handle-whitespace-before-in-scanf.patch
new file mode 100644
index 0000000000..f079ee3092
--- /dev/null
+++ b/main/musl/0064-handle-whitespace-before-in-scanf.patch
@@ -0,0 +1,61 @@
+From 9255dad97e7bfd4165d1aa0f93f2aae321a7a4d8 Mon Sep 17 00:00:00 2001
+From: Bartosz Brachaczek <b.brachaczek@gmail.com>
+Date: Sun, 9 Jul 2017 23:00:18 +0200
+Subject: [PATCH 22/30] handle whitespace before %% in scanf
+
+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 1ebc5cef..a7cd0923 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.3
+