From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56812) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRqm6-0001zA-Dn for qemu-devel@nongnu.org; Tue, 18 Aug 2015 19:58:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZRqm3-0000ob-5Y for qemu-devel@nongnu.org; Tue, 18 Aug 2015 19:58:38 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:62019 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRqm2-0000eA-VB for qemu-devel@nongnu.org; Tue, 18 Aug 2015 19:58:35 -0400 Received: from maestria.local.igalia.com ([192.168.10.14] helo=mail.igalia.com) by fanzine.igalia.com with esmtps (Cipher TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim) id 1ZRqlP-0005VO-AY for ; Wed, 19 Aug 2015 01:57:55 +0200 Received: from berto by mail.igalia.com with local (Exim) id 1ZRqlP-00042B-5v for ; Wed, 19 Aug 2015 01:57:55 +0200 Date: Wed, 19 Aug 2015 01:57:55 +0200 From: Alberto Garcia Message-ID: <20150818235754.GA31625@igalia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] QEMU produces invalid JSON due to locale-dependent code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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. Berto