1 --- vfscanf.c.orig Tue Nov 18 16:48:06 2003
2 +++ vfscanf.c Tue Nov 18 17:35:55 2003
4 #define CT_FLOAT 4 /* %[efgEFG] conversion */
6 static const u_char *__sccl(char *, const u_char *);
7 -static int parsefloat(FILE *, char *, char *);
9 +static int parsefloat(FILE *, char **, size_t);
10 +#endif /* FLOATING_POINT */
15 int flags; /* flags as defined above */
16 char *p0; /* saves original value of p when necessary */
17 int nassigned; /* number of fields assigned */
18 - int nconversions; /* number of conversions */
19 int nread; /* number of characters consumed from fp */
20 int base; /* base argument to conversion function */
21 char ccltab[256]; /* character class table for %[...] */
35 if (flags & SUPPRESS) /* ??? */
37 if (flags & SHORTSHORT)
73 /* scan a floating point number as if by strtod */
74 - if (width == 0 || width > sizeof(buf) - 1)
75 - width = sizeof(buf) - 1;
76 - if ((width = parsefloat(fp, buf, buf + width)) == 0)
77 + if ((width = parsefloat(fp, &pbuf, width)) == 0) {
82 if ((flags & SUPPRESS) == 0) {
83 if (flags & LONGDBL) {
84 - long double res = strtold(buf, &p);
85 + long double res = strtold(pbuf, &p);
86 *va_arg(ap, long double *) = res;
87 } else if (flags & LONG) {
88 - double res = strtod(buf, &p);
89 + double res = strtod(pbuf, &p);
90 *va_arg(ap, double *) = res;
92 - float res = strtof(buf, &p);
93 + float res = strtof(pbuf, &p);
94 *va_arg(ap, float *) = res;
96 - if (__scanfdebug && p - buf != width)
97 + if (__scanfdebug && p - pbuf != width)
106 #endif /* FLOATING_POINT */
110 - return (nconversions != 0 ? nassigned : EOF);
111 + return (nassigned ? nassigned : EOF);
117 #ifdef FLOATING_POINT
119 -parsefloat(FILE *fp, char *buf, char *end)
120 +parsefloat(FILE *fp, char **buf, size_t width)
126 char decpt = *localeconv()->decimal_point;
127 _Bool gotmantdig = 0, ishex = 0;
131 + s = (width == 0 ? BUF : width + 1);
132 + b = (char *)malloc(s);
139 * We set commit = p whenever the string we have read so far
140 * constitutes a valid representation of a floating point
142 * always necessary to read at least one character that doesn't
143 * match; thus, we can't short-circuit "infinity" or "nan(...)".
146 - for (p = buf; p < end; ) {
148 + for (p = b; width == 0 || p < e; ) {
152 @@ -1046,6 +1054,17 @@
157 + size_t diff = (p - b);
159 + b = (char *)reallocf(b, s);
170 @@ -1057,6 +1076,7 @@
172 __ungetc(*(u_char *)p, fp);
174 - return (commit - buf);
176 + return (commit - b);