From 6f1277a2e69e9f906a63c98b1ebb7ab734fad3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Thu, 11 Apr 2024 20:20:31 +0200 Subject: [PATCH] server: Fix invalid JSON caused by locale decimal conversion When creating JSON data, we must ensure that our decimal numbers are converted to a string with a "." as separator, otherwise it would be an invalid JSON. --- src/lib/clapper/features/server/clapper-server-json.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/clapper/features/server/clapper-server-json.c b/src/lib/clapper/features/server/clapper-server-json.c index 0f144296..288acbfa 100644 --- a/src/lib/clapper/features/server/clapper-server-json.c +++ b/src/lib/clapper/features/server/clapper-server-json.c @@ -41,9 +41,11 @@ _JSON_AUTO_COMMA \ g_string_append_printf (_json, "\"%s\":%" G_GUINT64_FORMAT, key, (guint64) val); -#define _ADD_KEY_VAL_DOUBLE(key, val) \ +#define _ADD_KEY_VAL_DOUBLE(key, val) { \ + gchar _buf[G_ASCII_DTOSTR_BUF_SIZE]; \ _JSON_AUTO_COMMA \ - g_string_append_printf (_json, "\"%s\":%.2lf", key, (gdouble) val); + g_string_append_printf (_json, "\"%s\":%s", key, \ + g_ascii_formatd (_buf, sizeof (_buf), "%.2f", val)); } #define _ADD_KEY_VAL_STRING(key, val) \ _JSON_AUTO_COMMA \