mirror of https://github.com/DaveGamble/cJSON
fix bug 2895595 from jshvrsn whereby values outside of INT_MIN/INT_MAX range are printed incorrectly as ints.
git-svn-id: http://svn.code.sf.net/p/cjson/code@17 e3330c51-1366-4df0-8b21-3ccf24e3d50e
This commit is contained in:
parent
69dca155a9
commit
0dbe29ffe8
3
cJSON.c
3
cJSON.c
|
@ -28,6 +28,7 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
#include <limits.h>
|
||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
|
|
||||||
#if defined(WINDOWS) || defined(__WIN32__) || defined(WIN32) || defined(_WIN32)
|
#if defined(WINDOWS) || defined(__WIN32__) || defined(WIN32) || defined(_WIN32)
|
||||||
|
@ -112,7 +113,7 @@ static char *print_number(cJSON *item)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
double d=item->valuedouble;
|
double d=item->valuedouble;
|
||||||
if (fabs(((double)item->valueint)-d)<=DBL_EPSILON)
|
if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN)
|
||||||
{
|
{
|
||||||
str=(char*)cJSON_malloc(21); // 2^64+1 can be represented in 21 chars.
|
str=(char*)cJSON_malloc(21); // 2^64+1 can be represented in 21 chars.
|
||||||
sprintf(str,"%d",item->valueint);
|
sprintf(str,"%d",item->valueint);
|
||||||
|
|
Loading…
Reference in New Issue