From b59b26c4bf35af5b7d969c4c5ca9f52b51cd19ef Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Wed, 13 Jun 2007 17:10:06 +0000 Subject: [PATCH] MFB: Fixed bug #41673 (json_encode breaks large numbers in arrays). --- ext/json/JSON_parser.c | 7 ++++++- ext/json/json.c | 10 ++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ext/json/JSON_parser.c b/ext/json/JSON_parser.c index 3e091864f9..64a90500da 100644 --- a/ext/json/JSON_parser.c +++ b/ext/json/JSON_parser.c @@ -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) { diff --git a/ext/json/json.c b/ext/json/json.c index 19f46f2d85..e2be08b1ee 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -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'); -- 2.50.1