From 0dbe29ffe8a772c5b5990ce7da00ccddd596f3d4 Mon Sep 17 00:00:00 2001 From: Dave Gamble Date: Wed, 11 Nov 2009 00:15:53 +0000 Subject: [PATCH] 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 --- cJSON.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index 28a50ba..2ba22fd 100644 --- a/cJSON.c +++ b/cJSON.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "cJSON.h" #if defined(WINDOWS) || defined(__WIN32__) || defined(WIN32) || defined(_WIN32) @@ -112,7 +113,7 @@ static char *print_number(cJSON *item) { char *str; 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. sprintf(str,"%d",item->valueint);