Loading...
--- Libc/Libc-391.2.10/stdio/FreeBSD/vfwscanf.c.patch
+++ Libc/Libc-498/stdio/FreeBSD/vfwscanf.c.patch
@@ -1,5 +1,5 @@
--- vfwscanf.c.orig 2004-11-25 11:38:36.000000000 -0800
-+++ vfwscanf.c 2005-02-23 16:25:00.000000000 -0800
++++ vfwscanf.c 2005-05-20 00:24:42.000000000 -0700
@@ -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 $");
@@ -108,8 +108,9 @@
goto input_failure;
if (wi != c) {
- __ungetwc(wi, fp);
+- goto input_failure;
+ __ungetwc(wi, fp, loc);
- goto input_failure;
++ goto match_failure;
}
nread++;
continue;
@@ -371,7 +372,7 @@
if (flags & POINTER)
*va_arg(ap, void **) =
(void *)(uintptr_t)res;
-@@ -684,47 +715,49 @@
+@@ -684,47 +715,45 @@
nassigned++;
}
nread += p - buf;
@@ -387,11 +388,8 @@
- 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 (pbuf)
-+ free(pbuf);
++ if ((width = parsefloat(fp, &pbuf, width, loc)) == 0)
goto match_failure;
-+ }
if ((flags & SUPPRESS) == 0) {
if (flags & LONGDBL) {
- long double res = wcstold(buf, &p);
@@ -413,7 +411,6 @@
}
nread += width;
- nconversions++;
-+ free(pbuf);
break;
+ }
#endif /* !NO_FLOATING_POINT */
@@ -433,27 +430,43 @@
{
wchar_t *commit, *p;
int infnanpos = 0;
-@@ -733,9 +766,18 @@
+@@ -733,9 +762,33 @@
S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS
} state = S_START;
wchar_t c;
- wchar_t decpt = (wchar_t)(unsigned char)*localeconv()->decimal_point;
-+ wchar_t decpt = (wchar_t)(unsigned char)*localeconv_l(loc)->decimal_point;
++ char *decimal_point;
++ wchar_t decpt;
_Bool gotmantdig = 0, ishex = 0;
-+ wchar_t *b, *e;
+-
++ static wchar_t *b = NULL;
++ static size_t bsiz = 0;
++ wchar_t *e;
+ size_t s;
-
-+ s = (width == 0 ? BUF : width + 1);
-+ b = (wchar_t *)malloc(s * sizeof(wchar_t));
-+ if (b == NULL) {
-+ *buf = NULL;
-+ return 0;
++
++ if (bsiz == 0) {
++ b = (wchar_t *)malloc(BUF * sizeof(wchar_t));
++ if (b == NULL) {
++ *buf = NULL;
++ return 0;
++ }
++ bsiz = BUF;
++ }
++ s = (width == 0 ? bsiz : (width + 1));
++ if (s > bsiz) {
++ b = (wchar_t *)reallocf(b, s * sizeof(wchar_t));
++ if (b == NULL) {
++ bsiz = 0;
++ *buf = NULL;
++ return 0;
++ }
++ bsiz = s;
+ }
+ e = b + (s - 1);
/*
* We set commit = p whenever the string we have read so far
* constitutes a valid representation of a floating point
-@@ -745,10 +787,10 @@
+@@ -745,10 +798,12 @@
* always necessary to read at least one character that doesn't
* match; thus, we can't short-circuit "infinity" or "nan(...)".
*/
@@ -462,12 +475,14 @@
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 +850,7 @@
+@@ -808,7 +863,7 @@
if (c == ')') {
commit = p;
infnanpos = -2;
@@ -476,7 +491,7 @@
goto parsedone;
break;
}
-@@ -824,7 +866,7 @@
+@@ -824,7 +879,7 @@
goto reswitch;
}
case S_DIGITS:
@@ -485,7 +500,7 @@
gotmantdig = 1;
else {
state = S_FRAC;
-@@ -841,7 +883,7 @@
+@@ -841,7 +896,7 @@
goto parsedone;
else
state = S_EXP;
@@ -494,7 +509,7 @@
commit = p;
gotmantdig = 1;
} else
-@@ -854,7 +896,7 @@
+@@ -854,7 +909,7 @@
else
goto reswitch;
case S_EXPDIGITS:
@@ -503,20 +518,24 @@
commit = p;
else
goto parsedone;
-@@ -862,16 +904,28 @@
+@@ -862,16 +917,32 @@
default:
abort();
}
+ if (p >= e) {
-+ size_t diff = (p - b);
++ ssize_t diff = (p - b);
++ ssize_t com = (commit - b);
+ s += BUF;
+ b = (wchar_t *)reallocf(b, s * sizeof(wchar_t));
+ if (b == NULL) {
++ bsiz = 0;
+ *buf = NULL;
+ return 0;
+ }
++ bsiz = s;
+ e = b + (s - 1);
+ p = b + diff;
++ commit = b + com;
+ }
*p++ = c;
c = WEOF;