summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/vfprintf.c
diff options
context:
space:
mode:
authormatthew <matthew@openbsd.org>2012-06-26 14:53:23 +0000
committermatthew <matthew@openbsd.org>2012-06-26 14:53:23 +0000
commit4ddf57cc6fd51b9a16ccfae3ce1d6ea529405a31 (patch)
treec97f0cf2a3852a3f1a980238ea563fef9bfcabf6 /lib/libc/stdio/vfprintf.c
parentAdd some more paranoia and make code clearer. Check that the required (diff)
downloadwireguard-openbsd-4ddf57cc6fd51b9a16ccfae3ce1d6ea529405a31.tar.xz
wireguard-openbsd-4ddf57cc6fd51b9a16ccfae3ce1d6ea529405a31.zip
Use nl_langinfo(RADIXCHAR) instead of localeconv()->decimal_point in
printf() and avoid calling it unless needed (i.e., when we have a floating point value to print). This isn't a big concern currently due to our limited locale support and current localeconv() implementation, but it's still technically a data race and implementing POSIX 2008 per-thread locales is likely to make it worse. nl_langinfo() isn't guaranteed by POSIX to be thread-safe either, but at least our current implementation is thread-safe and it's a simpler interface to keep that way. Printing floating point values isn't async-signal-safe anyway due to gdtoa()'s use of malloc(), so that's not an issue. ok deraadt, stsp, millert
Diffstat (limited to 'lib/libc/stdio/vfprintf.c')
-rw-r--r--lib/libc/stdio/vfprintf.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index 8deb37f40f9..b85f9a5a901 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfprintf.c,v 1.61 2011/07/06 19:53:52 stsp Exp $ */
+/* $OpenBSD: vfprintf.c,v 1.62 2012/06/26 14:53:23 matthew Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -41,6 +41,7 @@
#include <sys/mman.h>
#include <errno.h>
+#include <langinfo.h>
#include <limits.h>
#include <stdarg.h>
#include <stddef.h>
@@ -299,7 +300,7 @@ __vfprintf(FILE *fp, const char *fmt0, __va_list ap)
* D: expchar holds this character; '\0' if no exponent, e.g. %f
* F: at least two digits for decimal, at least one digit for hex
*/
- char *decimal_point = localeconv()->decimal_point;
+ char *decimal_point = NULL;
int signflag; /* true if float is negative */
union { /* floating point arguments %[aAeEfFgG] */
double dbl;
@@ -1014,6 +1015,8 @@ number: if ((dprec = prec) >= 0)
if ((flags & FPT) == 0) {
PRINT(cp, size);
} else { /* glue together f_p fragments */
+ if (decimal_point == NULL)
+ decimal_point = nl_langinfo(RADIXCHAR);
if (!expchar) { /* %[fF] or sufficiently short %[gG] */
if (expt <= 0) {
PRINT(zeroes, 1);