Browse Source

Fixed bug #41673 (json_encode breaks large numbers in arrays).

experimental/5.2-WITH_DRCP
Ilia Alshanetsky 19 years ago
parent
commit
9f28e21bb1
  1. 1
      NEWS
  2. 7
      ext/json/JSON_parser.c
  3. 14
      ext/json/json.c
  4. 4
      ext/json/tests/pass001.1.phpt

1
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

7
ext/json/JSON_parser.c

@ -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)
{

14
ext/json/json.c

@ -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');
}

4
ext/json/tests/pass001.1.phpt

@ -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"]=>

Loading…
Cancel
Save