qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] QEMU produces invalid JSON due to locale-dependent code
@ 2015-08-18 23:57 Alberto Garcia
  2015-08-24  8:58 ` Daniel P. Berrange
  2015-08-24 10:05 ` Markus Armbruster
  0 siblings, 2 replies; 17+ messages in thread
From: Alberto Garcia @ 2015-08-18 23:57 UTC (permalink / raw)
  To: qemu-devel

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

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2015-08-26 12:04 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).