diff --git a/ext/misc/json1.c b/ext/misc/json1.c index f6fb2eafec..2962df25e4 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -34,6 +34,11 @@ SQLITE_EXTENSION_INIT1 #define UNUSED_PARAM(X) (void)(X) +#ifndef LARGEST_INT64 +# define LARGEST_INT64 (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32)) +# define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64) +#endif + /* ** Versions of isspace(), isalnum() and isdigit() to which it is safe ** to pass signed char values. @@ -478,18 +483,35 @@ static void jsonReturn( sqlite3_result_int(pCtx, 0); break; } - case JSON_REAL: { - double r = strtod(pNode->u.zJContent, 0); - sqlite3_result_double(pCtx, r); - break; - } case JSON_INT: { sqlite3_int64 i = 0; const char *z = pNode->u.zJContent; if( z[0]=='-' ){ z++; } - while( z[0]>='0' && z[0]<='9' ){ i = i*10 + *(z++) - '0'; } + while( z[0]>='0' && z[0]<='9' ){ + unsigned v = *(z++) - '0'; + if( i>=LARGEST_INT64/10 ){ + if( z[0]>='0' && z[0]<='9' ) goto int_as_real; + if( v==9 ) goto int_as_real; + if( v==8 ){ + if( pNode->u.zJContent[0]=='-' ){ + sqlite3_result_int64(pCtx, SMALLEST_INT64); + goto int_done; + }else{ + goto int_as_real; + } + } + } + i = i*10 + v; + } if( pNode->u.zJContent[0]=='-' ){ i = -i; } sqlite3_result_int64(pCtx, i); + int_done: + break; + int_as_real: /* fall through to real */; + } + case JSON_REAL: { + double r = strtod(pNode->u.zJContent, 0); + sqlite3_result_double(pCtx, r); break; } case JSON_STRING: { diff --git a/manifest b/manifest index d0a55d2359..306b4988c5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sfts5\ssources\sfrom\sTESTSRC2\sin\smain.mk\sas\sthere\sis\sno\sSQLITE_TEST\scode\sin\ssaid\sfiles. -D 2015-10-09T17:54:10.922 +C Fix\sthe\sJSON1\sextension\sso\sthat\sit\srenders\sintegers\soutside\sthe\srange\nof\s-9223372036854775808\sto\s+9223372036854775807\sas\sfloating-point\snumbers. +D 2015-10-09T18:21:43.153 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in f0088ff0d2ac949fce6de7c00f13a99ac5bdb663 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -198,7 +198,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 4c84635c71c26cfa7c2e5848cf49fe2d2cfcd767 F ext/misc/ieee754.c b0362167289170627659e84173f5d2e8fee8566e -F ext/misc/json1.c e1822098b8131133f24800bda551c56877244ceb +F ext/misc/json1.c 2b26b004bf6f3bf0a63b7967d06f9db41701db6e F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c bcbee3c061b884eccb80e21651daaae8e1e43c63 F ext/misc/regexp.c af92cdaa5058fcec1451e49becc7ba44dba023dc @@ -1390,7 +1390,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8a4e19888f512c3ee95aa3040924fc932fbdab1a -R 38dcee8daf6135103e889e1478dbb9d1 -U dan -Z 6a0f067a32a63752086ec828c1e4d102 +P c1840639b8ce8314602cd2396a324de8fac98dbe +R 0a0d9dafaf6405334993e0ec52446217 +U drh +Z 3ad870ec9ba73f21ea47e4c129fbbfc2 diff --git a/manifest.uuid b/manifest.uuid index 4dfa4dc00f..0d52c70441 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c1840639b8ce8314602cd2396a324de8fac98dbe \ No newline at end of file +ae736e35fb59c9aed33a8c805cf2ecdee528051f \ No newline at end of file