spa: add locale independent spa_dtoa

And use this in spa_json_format_float() where we also avoid invalid
json floats.
Use json float format in some places where we serialize json floats.
Add a unit test.

See #2223
This commit is contained in:
Wim Taymans 2022-03-21 10:41:44 +01:00
parent 5f4d031db0
commit 2b16df4e89
6 changed files with 40 additions and 13 deletions

View file

@ -235,7 +235,7 @@ static int do_extension_stream_restore_write(struct client *client, uint32_t com
FILE *f;
char *ptr;
size_t size;
char key[1024];
char key[1024], buf[128];
spa_zero(map);
spa_zero(vol);
@ -260,7 +260,8 @@ static int do_extension_stream_restore_write(struct client *client, uint32_t com
if (vol.channels > 0) {
fprintf(f, ", \"volumes\": [");
for (i = 0; i < vol.channels; i++)
fprintf(f, "%s%f", (i == 0 ? " ":", "), vol.values[i]);
fprintf(f, "%s%s", (i == 0 ? " ":", "),
spa_json_format_float(buf, sizeof(buf), vol.values[i]));
fprintf(f, " ]");
}
if (map.channels > 0) {