keep the exponent when trimming zeroes with JSON_C_TO_STRING_NOZERO

This commit is contained in:
Javid Khan authored and Eric Hawicz committed 2026-11-08 21:41:15 -05:00
1 parent cdd8db0530
commit 7f4196213a
3 files changed
+22 -5

No files matched your search

+8 -5
View File
@@ -1328,15 +1328,18 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str
{
/* last useful digit, always keep 1 zero */
p++;
for (q = p; *q; q++)
for (q = p; is_plain_digit(*q); q++)
{
if (*q != '0')
p = q;
}
/* drop trailing zeroes */
if (*p != 0)
*(++p) = 0;
size = p - buf;
/* drop trailing zeroes, keeping any exponent after them */
if (is_plain_digit(*p))
{
p++;
memmove(p, q, strlen(q) + 1);
}
size = (int)strlen(buf);
}
}
// although unlikely, snprintf can fail