X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Fvfscanf.c;h=61b0edb159fbbec9e70c02f5d13202316a100631;hb=9c21f4342c787e04a9e31ad8a1d87a65c89968ca;hp=926d8a9d13d4c3aa455aa8bb6c4610ac742dde7e;hpb=03de77f5210addfd2ca2b35137152edfe2ab70be;p=musl diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c index 926d8a9d..61b0edb1 100644 --- a/src/stdio/vfscanf.c +++ b/src/stdio/vfscanf.c @@ -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}; @@ -291,7 +292,7 @@ int vfscanf(FILE *f, const char *fmt, va_list ap) 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;