qemu-devel
[Top][All Lists]
Advanced

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

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


From: Alberto Garcia
Subject: [Qemu-devel] QEMU produces invalid JSON due to locale-dependent code
Date: Wed, 19 Aug 2015 01:57:55 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

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



reply via email to

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