]> granicus.if.org Git - php/commitdiff
Fixed bug #41673 (json_encode breaks large numbers in arrays).
authorIlia Alshanetsky <iliaa@php.net>
Wed, 13 Jun 2007 17:07:58 +0000 (17:07 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 13 Jun 2007 17:07:58 +0000 (17:07 +0000)
NEWS
ext/json/JSON_parser.c
ext/json/json.c
ext/json/tests/pass001.1.phpt

diff --git a/NEWS b/NEWS
index 910ff2479658354676c6f34d08f1066aba186ba1..8f1ae9a6d6677e2dae74f3472c43a59c4f4d9f16 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -89,6 +89,7 @@ PHP                                                                        NEWS
 - Fixed altering $this via argument named "this". (Dmitry)
 - Fixed PHP CLI usage of php.ini from the binary location. (Hannes)
 - Fixed segfault in strripos(). (Tony, Joxean Koret)
+- Fixed bug #41673 (json_encode breaks large numbers in arrays). (Ilia)
 - Fixed bug #41525 (ReflectionParameter::getPosition() not available). (Marcus)
 - Fixed bug #41511 (Compile failure under IRIX 6.5.30 building md5.c). (Jani)
 - Fixed bug #41504 (json_decode() incorrectly decodes JSON arrays with empty
index 2f2d26812562bbbccaea4c46fe973ae96300ba13..9f46553f67fb053bb7fe0e30311544c4f2ab504b 100644 (file)
@@ -284,7 +284,12 @@ static void json_create_zval(zval **z, smart_str *buf, int type)
 
     if (type == IS_LONG)
     {
-        ZVAL_LONG(*z, atol(buf->c));
+       double d = zend_strtod(buf->c, NULL);
+       if (d > LONG_MAX) {
+               ZVAL_DOUBLE(*z, d);
+       } else {
+               ZVAL_LONG(*z, (long)d);
+       }
     }
     else if (type == IS_DOUBLE)
     {
index 737421f5aca452cc216ac3d500b633aaff937b7f..56507a2cbc833403f775f893582a72524992263f 100644 (file)
@@ -355,17 +355,9 @@ static void json_encode_r(smart_str *buf, zval *val TSRMLS_DC) {
 
                 if (!zend_isinf(dbl) && !zend_isnan(dbl)) {
                        len = spprintf(&d, 0, "%.*g", (int) EG(precision), dbl);
-                       if (d) {
-                               if (dbl > LONG_MAX && !memchr(d, '.', len)) {
-                                       smart_str_append_unsigned(buf, (unsigned long)Z_DVAL_P(val));
-                               } else {
-                                       smart_str_appendl(buf, d, len);
-                               }
-                               efree(d);
-                       }
-                }
-                else
-                {
+                       smart_str_appendl(buf, d, len);
+                       efree(d);
+                } else {
                     zend_error(E_WARNING, "[json] (json_encode_r) double %.9g does not conform to the JSON spec, encoded as 0.", dbl);
                     smart_str_appendc(buf, '0');
                 }
index 57a016b40bede2aef5477989cd639d706fe62e1c..828a6499f7accd03661c56730eafcbde3a135c1e 100644 (file)
@@ -573,7 +573,7 @@ array(14) {
     ["_empty_"]=>
     int(0)
     ["E no ."]=>
-    int(4000000000000)
+    %s(4000000000000)
     ["zero"]=>
     int(0)
     ["one"]=>
@@ -754,7 +754,7 @@ array(14) {
     [""]=>
     int(0)
     ["E no ."]=>
-    int(4000000000000)
+    %s(4000000000000)
     ["zero"]=>
     int(0)
     ["one"]=>