Loading...
--- Libc/Libc-391.2.10/stdio/FreeBSD/vfwscanf.c.patch
+++ Libc/Libc-583/stdio/FreeBSD/vfwscanf.c.patch
@@ -1,6 +1,6 @@
---- 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 @@
+--- 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.
#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 @@
+@@ -98,7 +100,9 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/v
#define CT_INT 3 /* %[dioupxX] conversion */
#define CT_FLOAT 4 /* %[efgEFG] conversion */
@@ -20,7 +20,7 @@
extern int __scanfdebug;
-@@ -116,7 +120,21 @@
+@@ -116,7 +120,21 @@ vfwscanf(FILE * __restrict fp, const wch
FLOCKFILE(fp);
ORIENT(fp, 1);
@@ -43,7 +43,7 @@
FUNLOCKFILE(fp);
return (ret);
}
-@@ -124,8 +142,9 @@
+@@ -124,8 +142,9 @@ vfwscanf(FILE * __restrict fp, const wch
/*
* 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 @@
+@@ -134,7 +153,6 @@ __vfwscanf(FILE * __restrict fp, const w
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,27 +163,30 @@
+@@ -145,31 +163,37 @@ __vfwscanf(FILE * __restrict fp, const w
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,18 +98,35 @@
+ __ungetwc(c, fp, loc);
continue;
}
- if (c != '%')
-@@ -180,15 +201,27 @@
+- 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++;
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)
-+ if ((wi = __fgetwc(fp, loc)) == WEOF)
- goto input_failure;
+- goto input_failure;
if (wi != c) {
- __ungetwc(wi, fp);
+- goto input_failure;
+ __ungetwc(wi, fp, loc);
- goto input_failure;
++ goto match_failure;
}
nread++;
continue;
@@ -129,7 +146,7 @@
case '*':
flags |= SUPPRESS;
goto again;
-@@ -307,7 +340,6 @@
+@@ -307,7 +349,6 @@ literal:
break;
case 'n':
@@ -137,7 +154,7 @@
if (flags & SUPPRESS) /* ??? */
continue;
if (flags & SHORTSHORT)
-@@ -343,11 +375,11 @@
+@@ -343,11 +384,11 @@ literal:
* that suppress this.
*/
if ((flags & NOSKIP) == 0) {
@@ -151,7 +168,7 @@
}
/*
-@@ -364,7 +396,7 @@
+@@ -364,7 +405,7 @@ literal:
p = va_arg(ap, wchar_t *);
n = 0;
while (width-- != 0 &&
@@ -160,7 +177,7 @@
if (!(flags & SUPPRESS))
*p++ = (wchar_t)wi;
n++;
-@@ -380,19 +412,19 @@
+@@ -380,19 +421,19 @@ literal:
n = 0;
mbs = initial;
while (width != 0 &&
@@ -186,7 +203,7 @@
break;
}
if (!(flags & SUPPRESS))
-@@ -410,7 +442,6 @@
+@@ -410,7 +451,6 @@ literal:
if (!(flags & SUPPRESS))
nassigned++;
}
@@ -194,7 +211,7 @@
break;
case CT_CCL:
-@@ -420,20 +451,20 @@
+@@ -420,20 +460,20 @@ literal:
/* take only those things in the class */
if ((flags & SUPPRESS) && (flags & LONG)) {
n = 0;
@@ -219,7 +236,7 @@
n = p - p0;
if (n == 0)
goto match_failure;
-@@ -444,16 +475,16 @@
+@@ -444,16 +484,16 @@ literal:
mbp = va_arg(ap, char *);
n = 0;
mbs = initial;
@@ -241,7 +258,7 @@
if (nconv == (size_t)-1)
goto input_failure;
if (nconv > width)
-@@ -468,14 +499,15 @@
+@@ -468,14 +508,15 @@ literal:
n++;
}
if (wi != WEOF)
@@ -259,7 +276,7 @@
break;
case CT_STRING:
-@@ -483,39 +515,39 @@
+@@ -483,39 +524,39 @@ literal:
if (width == 0)
width = (size_t)~0;
if ((flags & SUPPRESS) && (flags & LONG)) {
@@ -311,7 +328,7 @@
if (nconv == (size_t)-1)
goto input_failure;
if (nconv > width)
-@@ -530,13 +562,12 @@
+@@ -530,13 +571,12 @@ literal:
nread++;
}
if (wi != WEOF)
@@ -326,7 +343,7 @@
continue;
case CT_INT:
-@@ -546,7 +577,7 @@
+@@ -546,7 +586,7 @@ literal:
width = sizeof(buf) / sizeof(*buf) - 1;
flags |= SIGNOK | NDIGITS | NZDIGITS;
for (p = buf; width; width--) {
@@ -335,7 +352,7 @@
/*
* Switch on the character; `goto ok'
* if we accept it as a part of number.
-@@ -630,7 +661,7 @@
+@@ -630,7 +670,7 @@ literal:
* for a number. Stop accumulating digits.
*/
if (c != WEOF)
@@ -344,7 +361,7 @@
break;
ok:
/*
-@@ -646,22 +677,22 @@
+@@ -646,22 +686,22 @@ literal:
*/
if (flags & NDIGITS) {
if (p > buf)
@@ -371,7 +388,7 @@
if (flags & POINTER)
*va_arg(ap, void **) =
(void *)(uintptr_t)res;
-@@ -684,47 +715,49 @@
+@@ -684,47 +724,47 @@ literal:
nassigned++;
}
nread += p - buf;
@@ -387,11 +404,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);
@@ -407,13 +421,13 @@
*va_arg(ap, float *) = res;
}
- if (__scanfdebug && p - buf != width)
+- abort();
+ if (__scanfdebug && p - pbuf != width)
- abort();
++ LIBC_ABORT("p - pbuf %ld != width %ld", (long)(p - pbuf), width);
nassigned++;
}
nread += width;
- nconversions++;
-+ free(pbuf);
break;
+ }
#endif /* !NO_FLOATING_POINT */
@@ -427,25 +441,29 @@
}
#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 +766,18 @@
+@@ -733,9 +773,19 @@ parsefloat(FILE *fp, wchar_t *buf, wchar
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;
+-
++ wchar_t *b;
++ wchar_t *e;
+ size_t s;
-
-+ s = (width == 0 ? BUF : width + 1);
-+ b = (wchar_t *)malloc(s * sizeof(wchar_t));
-+ if (b == NULL) {
++
++ s = (width == 0 ? BUF : (width + 1));
++ if ((b = (wchar_t *)__parsefloat_buf(s * sizeof(wchar_t))) == NULL) {
+ *buf = NULL;
+ return 0;
+ }
@@ -453,7 +471,7 @@
/*
* 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 +795,12 @@ parsefloat(FILE *fp, wchar_t *buf, wchar
* always necessary to read at least one character that doesn't
* match; thus, we can't short-circuit "infinity" or "nan(...)".
*/
@@ -462,12 +480,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 +860,7 @@ reswitch:
if (c == ')') {
commit = p;
infnanpos = -2;
@@ -476,7 +496,7 @@
goto parsedone;
break;
}
-@@ -824,7 +866,7 @@
+@@ -824,7 +876,7 @@ reswitch:
goto reswitch;
}
case S_DIGITS:
@@ -485,7 +505,7 @@
gotmantdig = 1;
else {
state = S_FRAC;
-@@ -841,7 +883,7 @@
+@@ -841,7 +893,7 @@ reswitch:
goto parsedone;
else
state = S_EXP;
@@ -494,7 +514,7 @@
commit = p;
gotmantdig = 1;
} else
-@@ -854,7 +896,7 @@
+@@ -854,13 +906,26 @@ reswitch:
else
goto reswitch;
case S_EXPDIGITS:
@@ -503,24 +523,27 @@
commit = p;
else
goto parsedone;
-@@ -862,16 +904,28 @@
+ break;
default:
- abort();
- }
+- abort();
++ LIBC_ABORT("unknown state %d", state);
++ }
+ 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));
++ b = (wchar_t *)__parsefloat_buf(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)