From: "Daniel P. Berrange" <berrange@redhat.com>
To: Alberto Garcia <berto@igalia.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] QEMU produces invalid JSON due to locale-dependent code
Date: Mon, 24 Aug 2015 09:58:45 +0100 [thread overview]
Message-ID: <20150824085845.GB22295@redhat.com> (raw)
In-Reply-To: <20150818235754.GA31625@igalia.com>
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 :|
next prev parent reply other threads:[~2015-08-24 8:58 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-18 23:57 [Qemu-devel] QEMU produces invalid JSON due to locale-dependent code Alberto Garcia
2015-08-24 8:58 ` Daniel P. Berrange [this message]
2015-08-24 10:05 ` Markus Armbruster
2015-08-24 10:29 ` Alberto Garcia
2015-08-24 17:07 ` Markus Armbruster
2015-08-24 17:18 ` Eric Blake
2015-08-25 7:54 ` Markus Armbruster
2015-08-25 8:15 ` Alberto Garcia
2015-08-25 12:51 ` Markus Armbruster
2015-08-26 9:13 ` Alberto Garcia
2015-08-26 9:22 ` Daniel P. Berrange
2015-08-26 9:47 ` Markus Armbruster
2015-08-24 17:56 ` Daniel P. Berrange
2015-08-24 20:27 ` Eric Blake
2015-08-26 6:46 ` Gerd Hoffmann
2015-08-26 9:57 ` Daniel P. Berrange
2015-08-26 12:04 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150824085845.GB22295@redhat.com \
--to=berrange@redhat.com \
--cc=berto@igalia.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).