diff options
author | Dmitry Stogov <dmitry@zend.com> | 2016-04-26 13:06:16 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2016-04-26 13:06:16 +0300 |
commit | 8eeedb6e48f4d6651dd663f7228f6316a640fcc2 (patch) | |
tree | 2b1bcef2ff4eb14008abecc41ff2084153d0f643 /ext/standard | |
parent | 40b2048f721e4bb07017cb6c0368317594e2f8d9 (diff) | |
parent | 8f0ceb97cff0defa74294c5580e93386897b4933 (diff) | |
download | php-git-8eeedb6e48f4d6651dd663f7228f6316a640fcc2.tar.gz |
Merge branch 'PHP-7.0'
* PHP-7.0:
Fixed bug #72100 (implode() inserts garbage into resulting string when joins very big integer). (Mikhail Galanin)
Diffstat (limited to 'ext/standard')
-rw-r--r-- | ext/standard/string.c | 12 | ||||
-rw-r--r-- | ext/standard/tests/strings/bug72100.phpt | 18 |
2 files changed, 24 insertions, 6 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c index ab793b6217..e65d8cb2c5 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1229,16 +1229,16 @@ PHPAPI void php_implode(const zend_string *delim, zval *arr, zval *return_value) ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), tmp) { if (Z_TYPE_P(tmp) == IS_LONG) { - double val = Z_LVAL_P(tmp); + zend_long val = Z_LVAL_P(tmp); + *++strptr = NULL; ((zend_long *) (strings + numelems))[strptr - strings] = Z_LVAL_P(tmp); - if (val < 0) { - val = -10 * val; + if (val <= 0) { + len++; } - if (val < 10) { + while (val) { + val /= 10; len++; - } else { - len += (int) log10(10 * (double) val); } } else { *++strptr = zval_get_string(tmp); diff --git a/ext/standard/tests/strings/bug72100.phpt b/ext/standard/tests/strings/bug72100.phpt new file mode 100644 index 0000000000..7fcc0831b6 --- /dev/null +++ b/ext/standard/tests/strings/bug72100.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test implode() function, problems with big numbers +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--FILE-- +<?php +var_dump( implode(" ", ["hello long", 999999999999999999, PHP_INT_MAX])); +var_dump( implode(" ", ["hello negative long", -999999999999999999, PHP_INT_MIN] ) ); +var_dump( implode(" ", ["hello small long", -101, -100, -99, -90, -11, -10, -9, -1, 0, 1, 2, 9, 10, 11, 90, 99, 100, 101] ) ); +echo "Done\n"; +?> +--EXPECT-- +string(49) "hello long 999999999999999999 9223372036854775807" +string(60) "hello negative long -999999999999999999 -9223372036854775808" +string(76) "hello small long -101 -100 -99 -90 -11 -10 -9 -1 0 1 2 9 10 11 90 99 100 101" +Done |