Explorar o código

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
Dave Gamble %!s(int64=15) %!d(string=hai) anos
pai
achega
0dbe29ffe8
Modificáronse 1 ficheiros con 2 adicións e 1 borrados
  1. 2 1
      cJSON.c

+ 2 - 1
cJSON.c

@@ -28,6 +28,7 @@
 #include <math.h>
 #include <stdlib.h>
 #include <float.h>
+#include <limits.h>
 #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);