X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fstdio%2Fvfscanf.c;h=fe071e95cfbb6b81a3e43a7ec3fa65c5ce1ca590;hp=5c1e49b1536df9e366dbf6352be6ffff04ab5e67;hb=9cb6e6ea120cfaf1df9016883012d22fb57d43e1;hpb=18efeb320b763e541a7dbf61a7da1cbe13ab2be9 diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c index 5c1e49b1..fe071e95 100644 --- a/src/stdio/vfscanf.c +++ b/src/stdio/vfscanf.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -9,6 +8,7 @@ #include #include #include +#include #include "stdio_impl.h" #include "shgetc.h" @@ -71,7 +71,7 @@ static int readwc(int c, wchar_t **wcs, mbstate_t *st) return 0; } -int vfscanf(FILE *f, const char *fmt, va_list ap) +int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) { int width; int size; @@ -103,6 +103,7 @@ int vfscanf(FILE *f, const char *fmt, va_list ap) } if (*p != '%' || p[1] == '%') { p += *p=='%'; + shlim(f, 0); c = shgetc(f); if (c!=*p) { shunget(f); @@ -227,14 +228,14 @@ int vfscanf(FILE *f, const char *fmt, va_list ap) scanset[0] = 0; if (*p == '-') p++, scanset[1+'-'] = 1-invert; - if (*p == ']') p++, scanset[1+']'] = 1-invert; - for (; *p && *p != ']'; p++) { - if (*p=='-' && p[1] != ']') + else if (*p == ']') p++, scanset[1+']'] = 1-invert; + for (; *p != ']'; p++) { + if (!*p) goto fmt_fail; + if (*p=='-' && p[1] && p[1] != ']') for (c=p++[-1]; c<*p; c++) scanset[1+c] = 1-invert; scanset[1+*p] = 1-invert; } - if (!*p) goto fmt_fail; if (size == SIZE_l) { st = (mbstate_t){0}; @@ -284,14 +285,14 @@ int vfscanf(FILE *f, const char *fmt, va_list ap) int_common: x = __intscan(f, base, 0, ULLONG_MAX); if (!shcnt(f)) goto match_fail; - if (t=='p') *(void **)dest = (void *)(uintptr_t)x; + if (t=='p' && dest) *(void **)dest = (void *)(uintptr_t)x; else store_int(dest, size, x); break; case 'a': case 'A': case 'e': case 'E': case 'f': case 'F': case 'g': case 'G': - y = __floatscan(f, -1, size, 0); + y = __floatscan(f, size, 0); if (!shcnt(f)) goto match_fail; if (dest) switch (size) { case SIZE_def: @@ -312,6 +313,7 @@ int vfscanf(FILE *f, const char *fmt, va_list ap) if (readwc(c, &wcs, &st) < 0) goto input_fail; } + shunget(f); if (!mbsinit(&st)) goto input_fail; if (dest) *wcs++ = 0; break;