qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] QEMU produces invalid JSON due to locale-dependent code


From: Daniel P. Berrange
Subject: Re: [Qemu-devel] QEMU produces invalid JSON due to locale-dependent code
Date: Mon, 24 Aug 2015 09:58:45 +0100
User-agent: Mutt/1.5.23 (2014-03-12)

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 :|



reply via email to

[Prev in Thread] Current Thread [Next in Thread]