From a12aa2918535fd370419bd24b50a33974091c5a7 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 17 Apr 2012 23:08:58 -0400 Subject: [PATCH] fix failure to distinguish input/match failure in wide %[ scanf this also includes a related fix for vswscanf's read function, which was returning a spurious (uninitialized) character for empty strings. --- src/stdio/vfwscanf.c | 4 +++- src/stdio/vswscanf.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/stdio/vfwscanf.c b/src/stdio/vfwscanf.c index a52ba3a0..dbba8652 100644 --- a/src/stdio/vfwscanf.c +++ b/src/stdio/vfwscanf.c @@ -264,7 +264,9 @@ int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) } if (width) ungetwc(c, f); - if (!gotmatch) goto match_fail; + if (!gotmatch) + if (c>=0) goto match_fail; + else goto input_fail; if (*p==']') p++; while (*p!=']') { diff --git a/src/stdio/vswscanf.c b/src/stdio/vswscanf.c index 4396d7df..4c39f806 100644 --- a/src/stdio/vswscanf.c +++ b/src/stdio/vswscanf.c @@ -17,7 +17,7 @@ static size_t wstring_read(FILE *f, unsigned char *buf, size_t len) f->rend = f->buf + k; f->cookie = (void *)src; - if (!len) return 0; + if (!len || !k) return 0; *buf = *f->rpos++; return 1; -- 2.20.1