X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fstdio%2Fvfwscanf.c;h=de74fe0c4e5f59ad7d5ef8d742748ac106dbc8b3;hp=beb8e8fb9049f81a2755602c2bdee20c3056fc0a;hb=a749ba3adc2f3b4abfc68b21d4c3741b20c8f657;hpb=99fbf4cfdbb3b67f30d595a7f1c535ca17c2f969 diff --git a/src/stdio/vfwscanf.c b/src/stdio/vfwscanf.c index beb8e8fb..de74fe0c 100644 --- a/src/stdio/vfwscanf.c +++ b/src/stdio/vfwscanf.c @@ -181,8 +181,11 @@ int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) /* Transform ls,lc -> S,C */ if (size==SIZE_l && (t&15)==3) t&=~32; - if (t != 'n' && t != '[' && (t|32) != 'c') { - while (iswspace((c=getwc(f)))) pos++; + if (t != 'n') { + if (t != '[' && (t|32) != 'c') + while (iswspace((c=getwc(f)))) pos++; + else + c=getwc(f); if (c < 0) goto input_fail; ungetwc(c, f); } @@ -214,13 +217,14 @@ int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) break; case 's': + if (width < 1) width = -1; s = dest; 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--; + width-=(width>0); } if (width) ungetwc(c, f); if (s) *s = 0; @@ -228,8 +232,9 @@ int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) case 'S': wcs = dest; + if (width < 1) width = -1; while (width && !iswspace(c=getwc(f)) && c!=EOF) - width--, pos++, *wcs++ = c; + width-=(width>0), pos++, *wcs++ = c; if (width) ungetwc(c, f); if (wcs) *wcs = 0; break; @@ -243,6 +248,8 @@ int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) int gotmatch = 0; + if (width < 1) width = -1; + while (width) { if ((c=getwc(f))<0) break; if (in_set(p, c) == invert) @@ -255,7 +262,7 @@ int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) if (s) s+=l; } pos++; - width--; + width-=(width>0); gotmatch=1; } if (width) ungetwc(c, f);