From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48930) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTnag-0006rd-Vt for qemu-devel@nongnu.org; Mon, 24 Aug 2015 04:58:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTnad-00064N-8n for qemu-devel@nongnu.org; Mon, 24 Aug 2015 04:58:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52353) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTnad-00063n-4X for qemu-devel@nongnu.org; Mon, 24 Aug 2015 04:58:51 -0400 Date: Mon, 24 Aug 2015 09:58:45 +0100 From: "Daniel P. Berrange" Message-ID: <20150824085845.GB22295@redhat.com> References: <20150818235754.GA31625@igalia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20150818235754.GA31625@igalia.com> Subject: Re: [Qemu-devel] QEMU produces invalid JSON due to locale-dependent code Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alberto Garcia Cc: qemu-devel@nongnu.org On Wed, Aug 19, 2015 at 01:57:55AM +0200, Alberto Garcia wrote: > We have this code in qjson.c to produce JSON from a QFloat: > > QFloat *val = qobject_to_qfloat(obj); > char buffer[1024]; > int len; > > len = snprintf(buffer, sizeof(buffer), "%f", qfloat_get_double(val)); > while (len > 0 && buffer[len - 1] == '0') { > len--; > } > > > The problem here is that the output of snprintf() is locale-dependent, > so depending on the locale we might get a ',' as decimal separator. > That's not allowed by JSON and it actually breaks scripts/qmp/qmp. > > This seems to happen because of GTK+ calling setlocale(). The easiest > solution is probably to call setlocale(LC_NUMERIC, "C") before > snprintf() (or at start-up ui/gtk.c), but opinions are welcome. I reckon calling setlocale at a key point in the startup process would be a sensible thing todo. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|