Merge b64963332f8e5cdd7d65a645b21e316e394ab169 into cb8693b058ba302f4829ec6d03f609ac6f848546

This commit is contained in:
slark-yuxj 2023-07-09 18:15:48 +08:00 committed by GitHub
commit be60d05ede
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -567,6 +567,12 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
length = sprintf((char*)number_buffer, "%d", item->valueint);
}
else
{
if(item->valuedouble == item->valueint)
{
length = sprintf((char*)number_buffer, "%d", item->valueint);
}
else
{
/* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
length = sprintf((char*)number_buffer, "%1.15g", d);
@ -578,6 +584,7 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
length = sprintf((char*)number_buffer, "%1.17g", d);
}
}
}
/* sprintf failed or buffer overrun occurred */
if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1)))