Hi Jan, Jan Stary wrote on Thu, Jan 10, 2019 at 02:43:39PM +0100:
> The wprintf(3) manpage says > > The decimal point character is defined > in the program's locale (category LC_NUMERIC) > > but LC_NUMERIC is ignored in OpenBSD's C library, > as explained in setlocale(3). Right, i agree that is bogus. > Would it be an improvement to remove that sentence? I wouldn't remove it outright. That stuff is a very serious trap not only for the unwary, but also for experienced programmers. Less than a month ago, i discussed the matter with a senior programmer from the GNU project who has been maintaining important software over there for a long time and guess what he said? Something like "yes, you are right, that stuff is dangerous. I had a nasty bug in one of my programs just last week because a printf mangled numbers in a locale-dependent way i didn't anticipate." I think this is exactly what CAVEATS is good for. OK? Ingo Index: wprintf.3 =================================================================== RCS file: /cvs/src/lib/libc/stdio/wprintf.3,v retrieving revision 1.5 diff -u -p -r1.5 wprintf.3 --- wprintf.3 1 Dec 2017 10:56:07 -0000 1.5 +++ wprintf.3 10 Jan 2019 15:29:20 -0000 @@ -225,17 +225,17 @@ A .Cm + overrides a space if both are used. .It Sq Cm ' -Decimal conversions -.Cm ( d , u , +On +.Ox , +this flag has no effect. +On other systems, it may cause the insertion of +.Xr locale 1 Ns -dependent +thousands separator characters into the integral parts of arguments +of the +.Cm d , i , u , f , or -.Cm i ) -or the integral portion of a floating point conversion -.Cm ( f -or -.Cm F ) -should be grouped and separated by thousands using -the non-monetary separator returned by -.Xr localeconv 3 . +.Cm F +conversions. .El .It An optional decimal digit string specifying a minimum field width. @@ -578,10 +578,6 @@ is .Ql %% . .El .Pp -The decimal point -character is defined in the program's locale (category -.Dv LC_NUMERIC ) . -.Pp In no case does a non-existent or small field width cause truncation of a numeric field; if the result of a conversion is wider than the field width, the @@ -605,3 +601,21 @@ and functions conform to .St -isoC-99 . +.Sh CAVEATS +On systems other than +.Ox , +the +.Dv LC_NUMERIC +.Xr locale 1 +category can cause erratic output, for example different characters +substituted for the decimal point or thousands separator characters +inserted into numbers. +For security reasons, make sure that portable programs calling these +functions never call +.Xr setlocale 3 +with the +.Dv LC_ALL +or +.Dv LC_NUMERIC +categories but only use +.Dv LC_CTYPE .
