about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-04-17 22:15:33 -0400
committerRich Felker <dalias@aerifal.cx>2012-04-17 22:15:33 -0400
commit9ab180fa57f3a01b2004c3d19ad8dc3732f6069d (patch)
treefb6db9a8a3ae7d35cf67540676f56d68428e228a /src
parentdad40407705801c8bb597d5bc9a4eda562cae890 (diff)
downloadmusl-9ab180fa57f3a01b2004c3d19ad8dc3732f6069d.tar.gz
musl-9ab180fa57f3a01b2004c3d19ad8dc3732f6069d.tar.xz
musl-9ab180fa57f3a01b2004c3d19ad8dc3732f6069d.zip
fix broken %s and %[ with no width specifier in wide scanf
Diffstat (limited to 'src')
-rw-r--r--src/stdio/vfwscanf.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/stdio/vfwscanf.c b/src/stdio/vfwscanf.c
index beb8e8fb..a52ba3a0 100644
--- a/src/stdio/vfwscanf.c
+++ b/src/stdio/vfwscanf.c
@@ -214,13 +214,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 +229,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 +245,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 +259,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);