diff options
| author | Rich Felker <dalias@aerifal.cx> | 2012-04-17 19:37:31 -0400 | 
|---|---|---|
| committer | Rich Felker <dalias@aerifal.cx> | 2012-04-17 19:37:31 -0400 | 
| commit | 00722515729bb6943dc84a8c4aa9ccd715e48e74 (patch) | |
| tree | d3576b82f86a08569f220ccf2a6141790d4e7d88 | |
| parent | e0d9f780d171326a12bf9daf2af1e2f0c51c89f6 (diff) | |
| download | musl-00722515729bb6943dc84a8c4aa9ccd715e48e74.tar.gz | |
fix wide scanf to respect field width for strings
| -rw-r--r-- | src/stdio/vfwscanf.c | 11 | 
1 files changed, 7 insertions, 4 deletions
| diff --git a/src/stdio/vfwscanf.c b/src/stdio/vfwscanf.c index 4426a129..92b7fa40 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; | 
