summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/vfprintf.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2006-10-29 18:45:55 +0000
committerderaadt <deraadt@openbsd.org>2006-10-29 18:45:55 +0000
commit575363187b8d4227ad45d9eba18e69e123c9e936 (patch)
treed6ef99171b68a75dc0d95fedee3f2948388b2ea7 /lib/libc/stdio/vfprintf.c
parentFix TAILQ usage, preventing crashes (diff)
downloadwireguard-openbsd-575363187b8d4227ad45d9eba18e69e123c9e936.tar.xz
wireguard-openbsd-575363187b8d4227ad45d9eba18e69e123c9e936.zip
make __dtoa & strtod() thread-safe useing the same method as newer gdtoa
codebase. tested mostly by ckuethe and myself. __dtoa() use now requires a call to __freedtoa()
Diffstat (limited to 'lib/libc/stdio/vfprintf.c')
-rw-r--r--lib/libc/stdio/vfprintf.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index 24ca20a3ccc..e4173e3e4e9 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfprintf.c,v 1.38 2006/04/29 23:00:23 tedu Exp $ */
+/* $OpenBSD: vfprintf.c,v 1.39 2006/10/29 18:45:55 deraadt Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -117,6 +117,8 @@ __sbprintf(FILE *fp, const char *fmt, va_list ap)
#define BUF (MAXEXP+MAXFRACT+1) /* + decimal point */
#define DEFPREC 6
+extern char *__dtoa(double, int, int, int *, int *, char **);
+extern void __freedtoa(char *);
static char *cvt(double, int, int, char *, int *, int, int *);
static int exponent(char *, int, int);
@@ -174,6 +176,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 = NULL;
#endif
uintmax_t _umax; /* integer arguments %[diouxX] */
@@ -497,7 +500,9 @@ reswitch: switch (ch) {
}
flags |= FPT;
- cp = cvt(_double, prec, flags, &softsign,
+ if (dtoaresult)
+ __freedtoa(dtoaresult);
+ dtoaresult = cp = cvt(_double, prec, flags, &softsign,
&expt, ch, &ndig);
if (ch == 'g' || ch == 'G') {
if (expt <= -4 || expt > prec)
@@ -782,6 +787,10 @@ number: if ((dprec = prec) >= 0)
done:
FLUSH();
error:
+#ifdef FLOATING_POINT
+ if (dtoaresult)
+ __freedtoa(dtoaresult);
+#endif
if (argtable != NULL && argtable != statargtable) {
munmap(argtable, argtablesiz);
argtable = NULL;
@@ -1173,8 +1182,6 @@ __grow_type_table(unsigned char **typetable, int *tablesize)
#ifdef FLOATING_POINT
-extern char *__dtoa(double, int, int, int *, int *, char **);
-
static char *
cvt(double value, int ndigits, int flags, char *sign, int *decpt, int ch,
int *length)