From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14640 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: printf doesn't respect locale Date: Tue, 10 Sep 2019 13:33:51 -0400 Message-ID: <20190910173351.GR9017@brightrain.aerifal.cx> References: <20190909175452.GO9017@brightrain.aerifal.cx> <20190910163143.GI22009@port70.net> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="31899"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-14656-gllmg-musl=m.gmane.org@lists.openwall.com Tue Sep 10 19:34:06 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1i7k1m-0008Cs-8h for gllmg-musl@m.gmane.org; Tue, 10 Sep 2019 19:34:06 +0200 Original-Received: (qmail 1077 invoked by uid 550); 10 Sep 2019 17:34:04 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 1059 invoked from network); 10 Sep 2019 17:34:03 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:14640 Archived-At: On Tue, Sep 10, 2019 at 06:10:20PM +0100, Daniel Schoepe wrote: > Basically, someone used printf to produce json output and was unaware > that the radix used by printf was locale-dependent. When this was run > on a system with a non-English locale, it no longer produced valid > JSON as output. Yes, like you say it's not really a bug in correct software so much as a pitfall programmers are unaware of, that's hard to program around. But it can actually be a bug in correct *application* software due to incorrect library software. Various library software (I think glib or gtk, IIRC, among many others) calls setlocale(LC_ALL,"") behind the application's back, rather than trusting that the application set the locale the way it wants (incidentially, this is not thread-safe or library-safe and makes these libraries unsafe to use via dlopen or anywhere but at the top of main!). If the application only intends to set other categories, but leave LC_NUMERIC as "C", then it should rightfully expect a '.' radix point, but this expectation will be violated if certain third-party libraries are involved. Rich > On Tue, Sep 10, 2019 at 5:31 PM Szabolcs Nagy wrote: > > > > * Daniel Schoepe [2019-09-10 17:00:49 +0100]: > > > I'm also not a fan of this behavior, I actually stumbled across this > > > when tracking > > > down a bug the different radix usage caused. > > > > i'm interested in how this can cause a bug in correct software.