summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/vfwprintf.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/vfwprintf.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/vfwprintf.c')
-rw-r--r--lib/libc/stdio/vfwprintf.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/libc/stdio/vfwprintf.c b/lib/libc/stdio/vfwprintf.c
index b58985dd1ba..0619772323d 100644
--- a/lib/libc/stdio/vfwprintf.c
+++ b/lib/libc/stdio/vfwprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfwprintf.c,v 1.4 2011/05/09 19:49:51 stsp Exp $ */
+/* $OpenBSD: vfwprintf.c,v 1.5 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>
@@ -302,7 +303,7 @@ __vfwprintf(FILE * __restrict fp, const wchar_t * __restrict 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;
@@ -996,6 +997,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);