Loading...
stdio/FreeBSD/vfwscanf.c.patch Libc-583 Libc-391.2.6
--- Libc/Libc-583/stdio/FreeBSD/vfwscanf.c.patch
+++ Libc/Libc-391.2.6/stdio/FreeBSD/vfwscanf.c.patch
@@ -1,6 +1,6 @@
---- vfwscanf.c.orig	2009-02-15 03:11:22.000000000 -0800
-+++ vfwscanf.c	2009-02-16 00:10:06.000000000 -0800
-@@ -42,6 +42,8 @@ static char sccsid[] = "@(#)vfscanf.c	8.
+--- vfwscanf.c.orig	2004-11-25 11:38:36.000000000 -0800
++++ vfwscanf.c	2005-02-23 16:25:00.000000000 -0800
+@@ -42,6 +42,8 @@
  #include <sys/cdefs.h>
  __FBSDID("$FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.12 2004/05/02 20:13:29 obrien Exp $");
  
@@ -9,7 +9,7 @@
  #include "namespace.h"
  #include <ctype.h>
  #include <inttypes.h>
-@@ -98,7 +100,9 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/v
+@@ -98,7 +100,9 @@
  #define	CT_INT		3	/* %[dioupxX] conversion */
  #define	CT_FLOAT	4	/* %[efgEFG] conversion */
  
@@ -20,7 +20,7 @@
  
  extern int __scanfdebug;
  
-@@ -116,7 +120,21 @@ vfwscanf(FILE * __restrict fp, const wch
+@@ -116,7 +120,21 @@
  
  	FLOCKFILE(fp);
  	ORIENT(fp, 1);
@@ -43,7 +43,7 @@
  	FUNLOCKFILE(fp);
  	return (ret);
  }
-@@ -124,8 +142,9 @@ vfwscanf(FILE * __restrict fp, const wch
+@@ -124,8 +142,9 @@
  /*
   * Non-MT-safe version.
   */
@@ -55,7 +55,7 @@
  {
  	wint_t c;		/* character from format, or conversion */
  	size_t width;		/* field width, or 0 */
-@@ -134,7 +153,6 @@ __vfwscanf(FILE * __restrict fp, const w
+@@ -134,7 +153,6 @@
  	int flags;		/* flags as defined above */
  	wchar_t *p0;		/* saves original value of p when necessary */
  	int nassigned;		/* number of fields assigned */
@@ -63,7 +63,7 @@
  	int nread;		/* number of characters consumed from fp */
  	int base;		/* base argument to conversion function */
  	wchar_t buf[BUF];	/* buffer for numeric conversions */
-@@ -145,31 +163,37 @@ __vfwscanf(FILE * __restrict fp, const w
+@@ -145,27 +163,30 @@
  	char *mbp;		/* multibyte string pointer for %c %s %[ */
  	size_t nconv;		/* number of bytes in mb. conversion */
  	char mbbuf[MB_LEN_MAX];	/* temporary mb. character buffer */
@@ -98,35 +98,18 @@
 +				__ungetwc(c, fp, loc);
  			continue;
  		}
--		if (c != '%')
-+		if (c != '%') {
-+			if ((wi = __fgetwc(fp, loc)) == WEOF)
-+				goto input_failure;
- 			goto literal;
-+		}
- 		width = 0;
- 		flags = 0;
- 		/*
-@@ -179,16 +203,34 @@ __vfwscanf(FILE * __restrict fp, const w
- again:		c = *fmt++;
+ 		if (c != '%')
+@@ -180,15 +201,27 @@
  		switch (c) {
  		case '%':
-+		/* Consume leading white space */
-+			for(;;) {
-+				if ((wi = __fgetwc(fp, loc)) == WEOF)
-+					goto input_failure;
-+				if (!iswspace_l(wi, loc))
-+					break;
-+				nread++;
-+			}
  literal:
 -			if ((wi = __fgetwc(fp)) == WEOF)
--				goto input_failure;
++			if ((wi = __fgetwc(fp, loc)) == WEOF)
+ 				goto input_failure;
  			if (wi != c) {
 -				__ungetwc(wi, fp);
--				goto input_failure;
 +				__ungetwc(wi, fp, loc);
-+				goto match_failure;
+ 				goto input_failure;
  			}
  			nread++;
  			continue;
@@ -146,7 +129,7 @@
  		case '*':
  			flags |= SUPPRESS;
  			goto again;
-@@ -307,7 +349,6 @@ literal:
+@@ -307,7 +340,6 @@
  			break;
  
  		case 'n':
@@ -154,7 +137,7 @@
  			if (flags & SUPPRESS)	/* ??? */
  				continue;
  			if (flags & SHORTSHORT)
-@@ -343,11 +384,11 @@ literal:
+@@ -343,11 +375,11 @@
  		 * that suppress this.
  		 */
  		if ((flags & NOSKIP) == 0) {
@@ -168,7 +151,7 @@
  		}
  
  		/*
-@@ -364,7 +405,7 @@ literal:
+@@ -364,7 +396,7 @@
  					p = va_arg(ap, wchar_t *);
  				n = 0;
  				while (width-- != 0 &&
@@ -177,7 +160,7 @@
  					if (!(flags & SUPPRESS))
  						*p++ = (wchar_t)wi;
  					n++;
-@@ -380,19 +421,19 @@ literal:
+@@ -380,19 +412,19 @@
  				n = 0;
  				mbs = initial;
  				while (width != 0 &&
@@ -203,7 +186,7 @@
  							break;
  						}
  						if (!(flags & SUPPRESS))
-@@ -410,7 +451,6 @@ literal:
+@@ -410,7 +442,6 @@
  				if (!(flags & SUPPRESS))
  					nassigned++;
  			}
@@ -211,7 +194,7 @@
  			break;
  
  		case CT_CCL:
-@@ -420,20 +460,20 @@ literal:
+@@ -420,20 +451,20 @@
  			/* take only those things in the class */
  			if ((flags & SUPPRESS) && (flags & LONG)) {
  				n = 0;
@@ -236,7 +219,7 @@
  				n = p - p0;
  				if (n == 0)
  					goto match_failure;
-@@ -444,16 +484,16 @@ literal:
+@@ -444,16 +475,16 @@
  					mbp = va_arg(ap, char *);
  				n = 0;
  				mbs = initial;
@@ -258,7 +241,7 @@
  						if (nconv == (size_t)-1)
  							goto input_failure;
  						if (nconv > width)
-@@ -468,14 +508,15 @@ literal:
+@@ -468,14 +499,15 @@
  					n++;
  				}
  				if (wi != WEOF)
@@ -276,7 +259,7 @@
  			break;
  
  		case CT_STRING:
-@@ -483,39 +524,39 @@ literal:
+@@ -483,39 +515,39 @@
  			if (width == 0)
  				width = (size_t)~0;
  			if ((flags & SUPPRESS) && (flags & LONG)) {
@@ -328,7 +311,7 @@
  						if (nconv == (size_t)-1)
  							goto input_failure;
  						if (nconv > width)
-@@ -530,13 +571,12 @@ literal:
+@@ -530,13 +562,12 @@
  					nread++;
  				}
  				if (wi != WEOF)
@@ -343,7 +326,7 @@
  			continue;
  
  		case CT_INT:
-@@ -546,7 +586,7 @@ literal:
+@@ -546,7 +577,7 @@
  				width = sizeof(buf) / sizeof(*buf) - 1;
  			flags |= SIGNOK | NDIGITS | NZDIGITS;
  			for (p = buf; width; width--) {
@@ -352,7 +335,7 @@
  				/*
  				 * Switch on the character; `goto ok'
  				 * if we accept it as a part of number.
-@@ -630,7 +670,7 @@ literal:
+@@ -630,7 +661,7 @@
  				 * for a number.  Stop accumulating digits.
  				 */
  				if (c != WEOF)
@@ -361,7 +344,7 @@
  				break;
  		ok:
  				/*
-@@ -646,22 +686,22 @@ literal:
+@@ -646,22 +677,22 @@
  			 */
  			if (flags & NDIGITS) {
  				if (p > buf)
@@ -388,7 +371,7 @@
  				if (flags & POINTER)
  					*va_arg(ap, void **) =
  							(void *)(uintptr_t)res;
-@@ -684,47 +724,47 @@ literal:
+@@ -684,47 +715,49 @@
  				nassigned++;
  			}
  			nread += p - buf;
@@ -404,8 +387,11 @@
 -			    sizeof(*buf) - 1)
 -				width = sizeof(buf) / sizeof(*buf) - 1;
 -			if ((width = parsefloat(fp, buf, buf + width)) == 0)
-+			if ((width = parsefloat(fp, &pbuf, width, loc)) == 0)
++			if ((width = parsefloat(fp, &pbuf, width, loc)) == 0) {
++				if (pbuf)
++					free(pbuf);
  				goto match_failure;
++			}
  			if ((flags & SUPPRESS) == 0) {
  				if (flags & LONGDBL) {
 -					long double res = wcstold(buf, &p);
@@ -421,13 +407,13 @@
  					*va_arg(ap, float *) = res;
  				}
 -				if (__scanfdebug && p - buf != width)
--					abort();
 +				if (__scanfdebug && p - pbuf != width)
-+					LIBC_ABORT("p - pbuf %ld != width %ld", (long)(p - pbuf), width);
+ 					abort();
  				nassigned++;
  			}
  			nread += width;
 -			nconversions++;
++			free(pbuf);
  			break;
 +		}
  #endif /* !NO_FLOATING_POINT */
@@ -441,29 +427,25 @@
  }
  
  #ifndef NO_FLOATING_POINT
-+extern char *__parsefloat_buf(size_t s);  /* see vfscanf-fbsd.c */
-+
  static int
 -parsefloat(FILE *fp, wchar_t *buf, wchar_t *end)
 +parsefloat(FILE *fp, wchar_t **buf, size_t width, locale_t loc)
  {
  	wchar_t *commit, *p;
  	int infnanpos = 0;
-@@ -733,9 +773,19 @@ parsefloat(FILE *fp, wchar_t *buf, wchar
+@@ -733,9 +766,18 @@
  		S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS
  	} state = S_START;
  	wchar_t c;
 -	wchar_t decpt = (wchar_t)(unsigned char)*localeconv()->decimal_point;
-+	char *decimal_point;
-+	wchar_t decpt;
++	wchar_t decpt = (wchar_t)(unsigned char)*localeconv_l(loc)->decimal_point;
  	_Bool gotmantdig = 0, ishex = 0;
--
-+	wchar_t *b;
-+	wchar_t *e;
++	wchar_t *b, *e;
 +	size_t s;
-+
-+	s = (width == 0 ? BUF : (width + 1));
-+	if ((b = (wchar_t *)__parsefloat_buf(s * sizeof(wchar_t))) == NULL) {
+ 
++	s = (width == 0 ? BUF : width + 1);
++	b = (wchar_t *)malloc(s * sizeof(wchar_t));
++	if (b == NULL) {
 +		*buf = NULL;
 +		return 0;
 +	}
@@ -471,7 +453,7 @@
  	/*
  	 * We set commit = p whenever the string we have read so far
  	 * constitutes a valid representation of a floating point
-@@ -745,10 +795,12 @@ parsefloat(FILE *fp, wchar_t *buf, wchar
+@@ -745,10 +787,10 @@
  	 * always necessary to read at least one character that doesn't
  	 * match; thus, we can't short-circuit "infinity" or "nan(...)".
  	 */
@@ -480,14 +462,12 @@
  	c = WEOF;
 -	for (p = buf; p < end; ) {
 -		if ((c = __fgetwc(fp)) == WEOF)
-+	decimal_point = localeconv_l(loc)->decimal_point;
-+	mbtowc_l(&decpt, decimal_point, strlen(decimal_point), loc);
 +	for (p = b; width == 0 || p < e; ) {
 +		if ((c = __fgetwc(fp, loc)) == WEOF)
  			break;
  reswitch:
  		switch (state) {
-@@ -808,7 +860,7 @@ reswitch:
+@@ -808,7 +850,7 @@
  				if (c == ')') {
  					commit = p;
  					infnanpos = -2;
@@ -496,7 +476,7 @@
  					goto parsedone;
  				break;
  			}
-@@ -824,7 +876,7 @@ reswitch:
+@@ -824,7 +866,7 @@
  				goto reswitch;
  			}
  		case S_DIGITS:
@@ -505,7 +485,7 @@
  				gotmantdig = 1;
  			else {
  				state = S_FRAC;
-@@ -841,7 +893,7 @@ reswitch:
+@@ -841,7 +883,7 @@
  					goto parsedone;
  				else
  					state = S_EXP;
@@ -514,7 +494,7 @@
  				commit = p;
  				gotmantdig = 1;
  			} else
-@@ -854,13 +906,26 @@ reswitch:
+@@ -854,7 +896,7 @@
  			else
  				goto reswitch;
  		case S_EXPDIGITS:
@@ -523,27 +503,24 @@
  				commit = p;
  			else
  				goto parsedone;
- 			break;
+@@ -862,16 +904,28 @@
  		default:
--			abort();
-+			LIBC_ABORT("unknown state %d", state);
-+		}
+ 			abort();
+ 		}
 +		if (p >= e) {
-+			ssize_t diff = (p - b);
-+			ssize_t com = (commit - b);
++			size_t diff = (p - b);
 +			s += BUF;
-+			b = (wchar_t *)__parsefloat_buf(s * sizeof(wchar_t));
++			b = (wchar_t *)reallocf(b, s * sizeof(wchar_t));
 +			if (b == NULL) {
 +				*buf = NULL;
 +				return 0;
 +			}
 +			e = b + (s - 1);
 +			p = b + diff;
-+			commit = b + com;
- 		}
++		}
  		*p++ = c;
  		c = WEOF;
-@@ -868,10 +933,11 @@ reswitch:
+ 	}
  
  parsedone:
  	if (c != WEOF)