X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fstdio%2Fvfwscanf.c;h=beb8e8fb9049f81a2755602c2bdee20c3056fc0a;hp=4426a1296939ab811bcb129177d68b0fc7ad0375;hb=99fbf4cfdbb3b67f30d595a7f1c535ca17c2f969;hpb=73ec1d0495bb676012fd69491900ca8beb989ef7 diff --git a/src/stdio/vfwscanf.c b/src/stdio/vfwscanf.c index 4426a129..beb8e8fb 100644 --- a/src/stdio/vfwscanf.c +++ b/src/stdio/vfwscanf.c @@ -83,7 +83,7 @@ static int in_set(const wchar_t *set, int c) #undef ungetwc #define ungetwc(c,f) \ - ((f)->rend && (c)<128 ? *--(f)->rpos : ungetwc((c),(f))) + ((f)->rend && (c)<128U ? *--(f)->rpos : ungetwc((c),(f))) #endif int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) @@ -215,19 +215,22 @@ int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) case 's': s = dest; - while (!iswspace(c=getwc(f)) && c!=EOF) { + while (width && !iswspace(c=getwc(f)) && c!=EOF) { int l = wctomb(s?s:tmp, c); if (l<0) goto input_fail; if (s) s+=l; pos++; + width--; } + if (width) ungetwc(c, f); if (s) *s = 0; break; case 'S': wcs = dest; - while (!iswspace(c=getwc(f)) && c!=EOF) - pos++, *wcs++ = c; + while (width && !iswspace(c=getwc(f)) && c!=EOF) + width--, pos++, *wcs++ = c; + if (width) ungetwc(c, f); if (wcs) *wcs = 0; break; @@ -240,7 +243,7 @@ int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) int gotmatch = 0; - for (;;) { + while (width) { if ((c=getwc(f))<0) break; if (in_set(p, c) == invert) break; @@ -252,9 +255,10 @@ int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) if (s) s+=l; } pos++; + width--; gotmatch=1; } - ungetwc(c, f); + if (width) ungetwc(c, f); if (!gotmatch) goto match_fail;