diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2007-02-18 16:54:59 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2007-02-18 16:54:59 +0000 |
commit | 5e274ea47d2d31894b775fc8c171db88ee061c2e (patch) | |
tree | 2fac646495f4746fa861aab7cf889e4a0aaccf3c /ext/json/json.c | |
parent | 05584eb55a55816fdfe7ed4913d97334abec4f6c (diff) | |
download | php-git-5e274ea47d2d31894b775fc8c171db88ee061c2e.tar.gz |
Fixed bug #40503 (json_encode() value corruption on 32bit systems with
overflown values).
Diffstat (limited to 'ext/json/json.c')
-rw-r--r-- | ext/json/json.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/ext/json/json.c b/ext/json/json.c index 0f552d4fcd..1bfe3e0743 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -345,7 +345,7 @@ static void json_encode_r(smart_str *buf, zval *val TSRMLS_DC) { } break; case IS_LONG: - smart_str_append_long(buf, Z_LVAL_P(val)); + smart_str_append_long(buf, Z_LVAL_P(val)); break; case IS_DOUBLE: { @@ -353,14 +353,16 @@ static void json_encode_r(smart_str *buf, zval *val TSRMLS_DC) { int len; double dbl = Z_DVAL_P(val); - if (!zend_isinf(dbl) && !zend_isnan(dbl)) - { - len = spprintf(&d, 0, "%.9g", dbl); - if (d) - { - smart_str_appendl(buf, d, len); - efree(d); - } + if (!zend_isinf(dbl) && !zend_isnan(dbl)) { + len = spprintf(&d, 0, "%.9g", 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 { |