Fix JSON output for non-finite numbers.

Fixes #6015
This commit is contained in:
Gunnar Beutner 2014-04-15 12:21:40 +02:00
parent f48a6b429b
commit 9defdd74d9
1 changed files with 2 additions and 1 deletions

View File

@ -130,7 +130,8 @@ static char *print_number(cJSON *item)
str=(char*)cJSON_malloc(64); /* This is a nice tradeoff. */
if (str)
{
if (fabs(floor(d)-d)<=DBL_EPSILON) sprintf(str,"%.0f",d);
if (d != d) strcpy(str, "0");
else if (fabs(floor(d)-d)<=DBL_EPSILON) sprintf(str,"%.0f",d);
else sprintf(str,"%.*e",(int)log10(d) + 6,d);
}
}