summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/vfprintf.c
diff options
context:
space:
mode:
authortegge <tegge@FreeBSD.org>2001-02-15 22:12:50 +0000
committertegge <tegge@FreeBSD.org>2001-02-15 22:12:50 +0000
commit6a8ad1fd29cf8b7da27cdd40b7f2561db02f67a4 (patch)
tree2289e0be05fa981fe5e3711ecba0e98dc4d4abda /lib/libc/stdio/vfprintf.c
parent48633da620e77246fedda745c9d5b8d769693b32 (diff)
downloadFreeBSD-src-6a8ad1fd29cf8b7da27cdd40b7f2561db02f67a4.zip
FreeBSD-src-6a8ad1fd29cf8b7da27cdd40b7f2561db02f67a4.tar.gz
Remove freelists managed by Balloc/Bfree.
Change __dtoa to not free the string it allocated the previous time it was called. The caller now frees the string after usage if appropiate. PR: 15070 Reviewed by: deischen
Diffstat (limited to 'lib/libc/stdio/vfprintf.c')
-rw-r--r--lib/libc/stdio/vfprintf.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index ffdf522..49d4971 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -268,7 +268,7 @@ vfprintf(FILE *fp, const char *fmt0, va_list ap)
#define BUF (MAXEXP+MAXFRACT+1) /* + decimal point */
#define DEFPREC 6
-static char *cvt __P((double, int, int, char *, int *, int, int *));
+static char *cvt __P((double, int, int, char *, int *, int, int *, char **));
static int exponent __P((char *, int, int));
#else /* no FLOATING_POINT */
@@ -315,6 +315,7 @@ __vfprintf(FILE *fp, const char *fmt0, va_list ap)
int expsize; /* character count for expstr */
int ndig; /* actual number of digits returned by cvt */
char expstr[7]; /* buffer for exponent string */
+ char *dtoaresult; /* buffer allocated by dtoa */
#endif
u_long ulval; /* integer arguments %[diouxX] */
u_quad_t uqval; /* %q integers */
@@ -423,6 +424,9 @@ __vfprintf(FILE *fp, const char *fmt0, va_list ap)
}
+#ifdef FLOATING_POINT
+ dtoaresult = NULL;
+#endif
/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
if (cantwrite(fp))
return (EOF);
@@ -608,8 +612,12 @@ fp_begin: if (prec == -1)
break;
}
flags |= FPT;
+ if (dtoaresult != NULL) {
+ free(dtoaresult);
+ dtoaresult = NULL;
+ }
cp = cvt(_double, prec, flags, &softsign,
- &expt, ch, &ndig);
+ &expt, ch, &ndig, &dtoaresult);
if (ch == 'g' || ch == 'G') {
if (expt <= -4 || expt > prec)
ch = (ch == 'g') ? 'e' : 'E';
@@ -864,6 +872,10 @@ number: if ((dprec = prec) >= 0)
done:
FLUSH();
error:
+#ifdef FLOATING_POINT
+ if (dtoaresult != NULL)
+ free(dtoaresult);
+#endif
if (__sferror(fp))
ret = EOF;
if ((argtable != NULL) && (argtable != statargtable))
@@ -1195,11 +1207,11 @@ __grow_type_table (int nextarg, unsigned char **typetable, int *tablesize)
#ifdef FLOATING_POINT
-extern char *__dtoa __P((double, int, int, int *, int *, char **));
+extern char *__dtoa __P((double, int, int, int *, int *, char **, char **));
static char *
cvt(double value, int ndigits, int flags, char *sign, int *decpt,
- int ch, int *length)
+ int ch, int *length, char **dtoaresultp)
{
int mode, dsgn;
char *digits, *bp, *rve;
@@ -1221,7 +1233,8 @@ cvt(double value, int ndigits, int flags, char *sign, int *decpt,
*sign = '-';
} else
*sign = '\000';
- digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve);
+ digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve,
+ dtoaresultp);
if ((ch != 'g' && ch != 'G') || flags & ALT) {
/* print trailing zeros */
bp = digits + ndigits;
OpenPOWER on IntegriCloud