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

index 3e091864f9c57be5792c03de7303891d5ece93ea..64a90500da9b77da439beb211efea71d40a9f78a 100644 (file)
@@ -284,7 +284,12 @@ static void json_create_zval(zval **z, smart_str *buf, int type TSRMLS_DC)
 
     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 19f46f2d85826edf3d78cf7f242435c36f1455c1..e2be08b1eeed0937194ac9a1a52f767ec754eda3 100644 (file)
@@ -363,15 +363,9 @@ static void json_encode_r(smart_str *buf, zval *val TSRMLS_DC) /* {{{ */
                 double dbl = Z_DVAL_P(val);
 
                 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);
-                        }
+                       len = spprintf(&d, 0, "%.*g", (int) EG(precision), dbl);
+                       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');