fix failure to distinguish input/match failure in wide %[ scanf
authorRich Felker <dalias@aerifal.cx>
Wed, 18 Apr 2012 03:08:58 +0000 (23:08 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 18 Apr 2012 03:08:58 +0000 (23:08 -0400)
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
src/stdio/vswscanf.c

index a52ba3a07099bc5bb003f63c0ccbd1bb0dd4b840..dbba86526b9f6485a32e48fb16bfbd0e60c1ffed 100644 (file)
@@ -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!=']') {
index 4396d7df644d85c9749701bc4e3c2b2f4d361c33..4c39f80655ddccc8e3599008427710a4da864b16 100644 (file)
@@ -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;