1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

core: Warn when non-representable floats are coerced to int (#19760)

RFC: https://wiki.php.net/rfc/warnings-php-8-5#casting_out_of_range_floats_to_int
This commit is contained in:
Gina Peter Banyard
2025-09-21 23:53:16 +01:00
committed by GitHub
parent 5f00673a45
commit b4ed215299
62 changed files with 1107 additions and 275 deletions

View File

@@ -371,7 +371,7 @@ static inline zend_result fetch_array_elem(zval **result, zval *op1, zval *op2)
*result = zend_hash_index_find(Z_ARR_P(op1), Z_LVAL_P(op2));
return SUCCESS;
case IS_DOUBLE: {
zend_long lval = zend_dval_to_lval(Z_DVAL_P(op2));
zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(op2));
if (!zend_is_long_compatible(Z_DVAL_P(op2), lval)) {
return FAILURE;
}
@@ -459,7 +459,7 @@ static inline zend_result ct_eval_del_array_elem(zval *result, const zval *key)
zend_hash_index_del(Z_ARR_P(result), Z_LVAL_P(key));
break;
case IS_DOUBLE: {
zend_long lval = zend_dval_to_lval(Z_DVAL_P(key));
zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key));
if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) {
return FAILURE;
}
@@ -504,7 +504,7 @@ static inline zend_result ct_eval_add_array_elem(zval *result, zval *value, cons
value = zend_hash_index_update(Z_ARR_P(result), Z_LVAL_P(key), value);
break;
case IS_DOUBLE: {
zend_long lval = zend_dval_to_lval(Z_DVAL_P(key));
zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key));
if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) {
return FAILURE;
}

View File

@@ -5283,6 +5283,7 @@ ZEND_API bool zend_may_throw_ex(const zend_op *opline, const zend_ssa_op *ssa_op
case ZEND_CAST:
switch (opline->extended_value) {
case IS_LONG:
return (t1 & (MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_OBJECT));
case IS_DOUBLE:
return (t1 & MAY_BE_OBJECT);
case IS_STRING:

View File

@@ -12,4 +12,4 @@ try {
}
?>
--EXPECT--
Implicit conversion from float INF to int loses precision
The float INF is not representable as an int, cast occurred

View File

@@ -27,11 +27,11 @@ new foo;
?>
--EXPECTF--
Deprecated: Implicit conversion from float 3428599296 to int loses precision in %s on line %d
Warning: The float 3428599296 is not representable as an int, cast occurred in %s on line %d
Deprecated: Implicit conversion from float 3459455488 to int loses precision in %s on line %d
Warning: The float 3459455488 is not representable as an int, cast occurred in %s on line %d
Deprecated: Implicit conversion from float 3459616768 to int loses precision in %s on line %d
Warning: The float 3459616768 is not representable as an int, cast occurred in %s on line %d
array(3) {
[-866368000]=>
int(1)
@@ -41,10 +41,10 @@ array(3) {
int(3)
}
Deprecated: Implicit conversion from float 3459455488 to int loses precision in %s on line %d
Warning: The float 3459455488 is not representable as an int, cast occurred in %s on line %d
int(2)
Deprecated: Implicit conversion from float 3459616768 to int loses precision in %s on line %d
Warning: The float 3459616768 is not representable as an int, cast occurred in %s on line %d
array(1) {
[-835350528]=>
int(3)

View File

@@ -32,7 +32,7 @@ class lib {
function stream_stat() {
return [
'dev' => 3632233996,
'dev' => PHP_INT_MAX,
'size' => strlen($this->bytes),
'ino' => $this->ino
];

View File

@@ -11,6 +11,6 @@ $a=[];
?>
DONE
--EXPECTF--
Err: Implicit conversion from float %f to int loses precision
Err: The float %f is not representable as an int, cast occurred
Err: Undefined array key %i
DONE

View File

@@ -20,10 +20,19 @@ foreach ($doubles as $d) {
echo "Done\n";
?>
--EXPECT--
--EXPECTF--
Warning: The float 2147483648 is not representable as an int, cast occurred in %s on line %d
int(-2147483648)
Warning: The float 2147483649 is not representable as an int, cast occurred in %s on line %d
int(-2147483647)
Warning: The float 2147483658 is not representable as an int, cast occurred in %s on line %d
int(-2147483638)
Warning: The float 2147483748 is not representable as an int, cast occurred in %s on line %d
int(-2147483548)
Warning: The float 2147484648 is not representable as an int, cast occurred in %s on line %d
int(-2147482648)
Done

View File

@@ -22,10 +22,16 @@ foreach ($doubles as $d) {
echo "Done\n";
?>
--EXPECT--
--EXPECTF--
int(9223372036854775807)
Warning: The float %f is not representable as an int, cast occurred in %s on line %d
int(-9223372036854775808)
Warning: The float %f is not representable as an int, cast occurred in %s on line %d
int(-9223372036854775808)
Warning: The float %f is not representable as an int, cast occurred in %s on line %d
int(0)
int(-9223372036854775808)
int(-9223372036854775808)

View File

@@ -20,10 +20,18 @@ foreach ($doubles as $d) {
echo "Done\n";
?>
--EXPECT--
--EXPECTF--
int(-2147483648)
Warning: The float -2147483649 is not representable as an int, cast occurred in %s on line %d
int(2147483647)
Warning: The float -2147483658 is not representable as an int, cast occurred in %s on line %d
int(2147483638)
Warning: The float -2147483748 is not representable as an int, cast occurred in %s on line %d
int(2147483548)
Warning: The float -2147484648 is not representable as an int, cast occurred in %s on line %d
int(2147482648)
Done

View File

@@ -132,6 +132,93 @@ OUTPUT;
$EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s';
const EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS = <<<OUTPUT
Read before write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: Undefined array key 0 in %s on line %d
NULL
Write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Read:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(5)
Read-Write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
isset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(true)
empty():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(false)
null coalesce:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(25)
Reference to dimension:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Value of reference:
int(25)
Value of container dimension after write to reference (should be int(100) if successful):
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(100)
unset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested read:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: Undefined array key 0 in %s on line %d
Warning: Trying to access array offset on null in %s on line 74
NULL
Nested write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested Read-Write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested isset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(true)
Nested empty():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(false)
Nested null coalesce:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(30)
Nested unset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
OUTPUT;
$EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS) . '$/s';
const EXPECTED_OUTPUT_NULL_OFFSETS = <<<OUTPUT
Read before write:
@@ -452,6 +539,7 @@ foreach ($offsets as $dimension) {
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_NULL_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_NULL_OFFSET
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
@@ -484,6 +572,7 @@ foreach ($offsets as $offset) {
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_NULL_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_NULL_OFFSET
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS

View File

@@ -132,6 +132,93 @@ OUTPUT;
$EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s';
const EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS = <<<OUTPUT
Read before write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: Undefined array key 0 in %s on line %d
NULL
Write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Read:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(5)
Read-Write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
isset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(true)
empty():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(false)
null coalesce:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(25)
Reference to dimension:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Value of reference:
int(25)
Value of container dimension after write to reference (should be int(100) if successful):
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(100)
unset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested read:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: Undefined array key 0 in %s on line %d
Warning: Trying to access array offset on null in %s on line 74
NULL
Nested write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested Read-Write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested isset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(true)
Nested empty():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(false)
Nested null coalesce:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(30)
Nested unset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
OUTPUT;
$EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS) . '$/s';
const EXPECTED_OUTPUT_NULL_OFFSETS = <<<OUTPUT
Read before write:
@@ -356,6 +443,7 @@ foreach ($offsets as $dimension) {
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_NULL_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
) {
@@ -384,6 +472,7 @@ foreach ($offsets as $offset) {
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_NULL_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
) {

View File

@@ -13,6 +13,6 @@ x($y);
var_dump($y);
?>
--EXPECT--
Err: Implicit conversion from float 1.0E+20 to int loses precision
Err: The float 1.0E+20 is not representable as an int, cast occurred
array(0) {
}

View File

@@ -135,6 +135,93 @@ OUTPUT;
$EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s';
const EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS = <<<OUTPUT
Read before write:
Warning: Trying to access array offset on false in %s on line %d
NULL
Write:
Deprecated: Automatic conversion of false to array is deprecated in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Read:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(5)
Read-Write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
isset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(true)
empty():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(false)
null coalesce:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(25)
Reference to dimension:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Value of reference:
int(25)
Value of container dimension after write to reference (should be int(100) if successful):
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(100)
unset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested read:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: Undefined array key 0 in %s on line %d
Warning: Trying to access array offset on null in %s on line %d
NULL
Nested write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested Read-Write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested isset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(true)
Nested empty():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(false)
Nested null coalesce:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(30)
Nested unset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
OUTPUT;
$EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS) . '$/s';
const EXPECTED_OUTPUT_NULL_OFFSETS = <<<OUTPUT
Read before write:
@@ -363,6 +450,7 @@ foreach ($offsets as $dimension) {
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_NULL_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
) {
@@ -391,6 +479,7 @@ foreach ($offsets as $offset) {
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_NULL_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
) {

View File

@@ -131,6 +131,91 @@ OUTPUT;
$EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s';
const EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS = <<<OUTPUT
Read before write:
Warning: Trying to access array offset on null in %s on line %d
NULL
Write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Read:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(5)
Read-Write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
isset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(true)
empty():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(false)
null coalesce:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(25)
Reference to dimension:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Value of reference:
int(25)
Value of container dimension after write to reference (should be int(100) if successful):
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(100)
unset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested read:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: Undefined array key 0 in %s on line %d
Warning: Trying to access array offset on null in %s on line %d
NULL
Nested write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested Read-Write:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested isset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(true)
Nested empty():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(false)
Nested null coalesce:
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(30)
Nested unset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
OUTPUT;
$EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS) . '$/s';
const EXPECTED_OUTPUT_NULL_OFFSETS = <<<OUTPUT
Read before write:
@@ -353,6 +438,7 @@ foreach ($offsets as $dimension) {
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_NULL_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
) {
@@ -381,6 +467,7 @@ foreach ($offsets as $offset) {
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_NULL_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
) {

View File

@@ -280,7 +280,7 @@ OUTPUT;
$EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE) . '$/s';
const EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE = <<<OUTPUT
const EXPECTF_OUTPUT_FLOAT_WITH_FRACTIONAL_OUT_OF_RANGE_OFFSETS = <<<OUTPUT
Read before write:
Warning: String offset cast occurred in %s on line %d
@@ -349,9 +349,78 @@ Cannot use string offset as an array
OUTPUT;
$EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE) . '$/s';
$EXPECTF_OUTPUT_FLOAT_WITH_FRACTIONAL_OUT_OF_RANGE_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_WITH_FRACTIONAL_OUT_OF_RANGE_OFFSETS) . '$/s';
const EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS = <<<OUTPUT
const EXPECTF_OUTPUT_FLOAT_WITH_FRACTIONAL_OFFSETS = <<<OUTPUT
Read before write:
Warning: String offset cast occurred in %s on line %d
Warning: Uninitialized string offset %i in %s on line %d
string(0) ""
Write:
Warning: String offset cast occurred in %s on line %d
Read:
Warning: String offset cast occurred in %s on line %d
string(1) "5"
Read-Write:
Warning: String offset cast occurred in %s on line %d
Cannot use assign-op operators with string offsets
isset():
Deprecated: Implicit conversion from float %f to int loses precision in %s on line %d
bool(true)
empty():
Deprecated: Implicit conversion from float %f to int loses precision in %s on line %d
bool(false)
null coalesce:
string(1) "5"
Reference to dimension:
Warning: String offset cast occurred in %s on line %d
Cannot create references %s string offsets
unset():
Cannot unset string offsets
Nested read:
Warning: String offset cast occurred in %s on line %d
Warning: String offset cast occurred in %s on line %d
Warning: Uninitialized string offset %i in %s on line %d
string(0) ""
Nested write:
Warning: String offset cast occurred in %s on line %d
Cannot use string offset as an array
Nested Read-Write:
Warning: String offset cast occurred in %s on line %d
Cannot use string offset as an array
Nested isset():
Deprecated: Implicit conversion from float %f to int loses precision in %s on line %d
bool(false)
Nested empty():
Deprecated: Implicit conversion from float %f to int loses precision in %s on line %d
bool(true)
Nested null coalesce:
string(7) "default"
Nested unset():
Warning: String offset cast occurred in %s on line %d
Cannot use string offset as an array
OUTPUT;
$EXPECTF_OUTPUT_FLOAT_WITH_FRACTIONAL_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_WITH_FRACTIONAL_OFFSETS) . '$/s';
const EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS = <<<OUTPUT
Read before write:
Warning: String offset cast occurred in %s on line %d
@@ -371,10 +440,14 @@ Warning: String offset cast occurred in %s on line %d
Cannot use assign-op operators with string offsets
isset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
bool(true)
empty():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
bool(false)
null coalesce:
@@ -401,10 +474,14 @@ Warning: String offset cast occurred in %s on line %d
Cannot use string offset as an array
Nested isset():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
bool(true)
Nested empty():
Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
bool(false)
Nested null coalesce:
@@ -416,7 +493,7 @@ Cannot use string offset as an array
OUTPUT;
$EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS) . '$/s';
$EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS) . '$/s';
const EXPECTED_OUTPUT_INVALID_OFFSETS = <<<OUTPUT
Read before write:
@@ -648,8 +725,9 @@ foreach ($offsets as $dimension) {
&& !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_TO_0_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput)
&& !preg_match($EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTF_OUTPUT_FLOAT_WITH_FRACTIONAL_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTF_OUTPUT_FLOAT_WITH_FRACTIONAL_OUT_OF_RANGE_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_INVALID_OFFSETS_AS_STRINGS
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_REGEX, $varOutput)
@@ -682,8 +760,9 @@ foreach ($offsets as $offset) {
&& !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_TO_0_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput)
&& !preg_match($EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTF_OUTPUT_FLOAT_WITH_FRACTIONAL_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTF_OUTPUT_FLOAT_WITH_FRACTIONAL_OUT_OF_RANGE_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_INVALID_OFFSETS_AS_STRINGS
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_REGEX, $varOutput)

View File

@@ -85,7 +85,7 @@ function expectf_to_regex(string $wanted): string
'%d' => '\d+',
'%x' => '[0-9a-fA-F]+',
'%f' => '[+-]?(?:\d+|(?=\.\d))(?:\.\d+)?(?:[Ee][+-]?\d+)?',
'%F' => '([+-]?(?:\d+|(?=\.\d))(?:\.\d+)?(?:[Ee][+-]?\d+)?)|(NAN)|(INF)',
'%F' => '([+-]?(?:\d+|(?=\.\d))(?:\.\d+)?(?:[Ee][+-]?\d+)?)|(NAN)|(INF)|([+-]?\d+)',
'%c' => '.',
'%0' => '\x00',
]);

View File

@@ -8,7 +8,7 @@ if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
?>
--FILE--
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
error_reporting(E_ALL ^ E_DEPRECATED ^ E_WARNING);
$binaryOperators = [
"==",

View File

@@ -23,10 +23,21 @@ if (PHP_INT_SIZE != 4)
}
?>
--EXPECT--
--EXPECTF--
Warning: The float -4.000000000000001E+21 is not representable as an int, cast occurred in %s on line %d
int(-2056257536)
Warning: The float -4.0000000000000005E+21 is not representable as an int, cast occurred in %s on line %d
int(-2055733248)
Warning: The float -4.0E+21 is not representable as an int, cast occurred in %s on line %d
int(-2055208960)
Warning: The float -3.9999999999999995E+21 is not representable as an int, cast occurred in %s on line %d
int(-2054684672)
Warning: The float -3.999999999999999E+21 is not representable as an int, cast occurred in %s on line %d
int(-2054160384)
Warning: The float -2147483649.8 is not representable as an int, cast occurred in %s on line %d
int(2147483647)

View File

@@ -21,9 +21,18 @@ if (PHP_INT_SIZE != 8)
}
?>
--EXPECT--
--EXPECTF--
Warning: The float -4.000000000000001E+21 is not representable as an int, cast occurred in %s on line %d
int(2943463994971652096)
Warning: The float -4.0000000000000005E+21 is not representable as an int, cast occurred in %s on line %d
int(2943463994972176384)
Warning: The float -4.0E+21 is not representable as an int, cast occurred in %s on line %d
int(2943463994972700672)
Warning: The float -3.9999999999999995E+21 is not representable as an int, cast occurred in %s on line %d
int(2943463994973224960)
Warning: The float -3.999999999999999E+21 is not representable as an int, cast occurred in %s on line %d
int(2943463994973749248)

View File

@@ -1,5 +1,5 @@
--TEST--
Explicit (int) cast must not warn
Explicit (int) cast must not warn if value is representable
--SKIPIF--
<?php
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
@@ -25,14 +25,24 @@ foreach($values as $value) {
}
?>
--EXPECT--
--EXPECTF--
int(3)
int(3)
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d
int(0)
Warning: The float 1.0E+301 is not representable as an int, cast occurred in %s on line %d
int(0)
Warning: The float NAN is not representable as an int, cast occurred in %s on line %d
int(0)
int(3)
int(3)
Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d
int(9223372036854775807)
Warning: The float-string "1.0E+301" is not representable as an int, cast occurred in %s on line %d
int(9223372036854775807)
int(0)

View File

@@ -25,14 +25,24 @@ foreach($values as $value) {
}
?>
--EXPECT--
--EXPECTF--
int(3)
int(3)
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d
int(0)
Warning: The float 1.0E+301 is not representable as an int, cast occurred in %s on line %d
int(0)
Warning: The float NAN is not representable as an int, cast occurred in %s on line %d
int(0)
int(3)
int(3)
Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d
int(2147483647)
Warning: The float-string "1.0E+301" is not representable as an int, cast occurred in %s on line %d
int(2147483647)
int(0)

View File

@@ -0,0 +1,19 @@
--TEST--
Non rep float string to int conversions should not crash when modified
--FILE--
<?php
set_error_handler(function ($errno, $errstr) {
global $b;
$b = null;
echo $errstr, "\n";
});
$a = "1.0E+" . rand(40,42);
$b = &$a;
var_dump($b | 1);
?>
--EXPECTF--
The float-string "1.0E+4%d" is not representable as an int, cast occurred
Implicit conversion from float-string "1.0E+4%d" to int loses precision
int(%d)

View File

@@ -0,0 +1,17 @@
--TEST--
Non rep float string to int conversions should not crash when modified
--FILE--
<?php
set_error_handler(function ($errno, $errstr) {
global $ary;
$ary = null;
echo $errstr, "\n";
});
$ary = [rand()];
unset($ary[1.0E+42]);
?>
--EXPECT--
The float 1.0E+42 is not representable as an int, cast occurred

View File

@@ -0,0 +1,18 @@
--TEST--
Non rep float string to int conversions should not crash when modified
--FILE--
<?php
set_error_handler(function ($errno, $errstr) {
global $ary;
$ary = null;
echo $errstr, "\n";
});
$ary = [rand()];
var_dump(isset($ary[1.0E+42]));
?>
--EXPECT--
The float 1.0E+42 is not representable as an int, cast occurred
bool(false)

View File

@@ -0,0 +1,18 @@
--TEST--
Non rep float string to int conversions should not crash when modified
--FILE--
<?php
set_error_handler(function ($errno, $errstr) {
global $ary;
$ary = null;
echo $errstr, "\n";
});
$ary = [rand()];
var_dump(\array_key_exists(1.0E+42, $ary));
?>
--EXPECT--
The float 1.0E+42 is not representable as an int, cast occurred
bool(false)

View File

@@ -23,12 +23,15 @@ var_dump($array[$string_float]);
?>
--EXPECTF--
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d
int(0)
Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d
bool(true)
Deprecated: Implicit conversion from float 1.0E+121 to int loses precision in %s on line %d
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d
Deprecated: Implicit conversion from float 1.0E+121 to int loses precision in %s on line %d
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d
array(2) {
[0]=>
string(11) "Large float"
@@ -42,13 +45,13 @@ array(2) {
string(18) "String large float"
}
Deprecated: Implicit conversion from float 1.0E+121 to int loses precision in %s on line %d
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d
string(1) "0"
Warning: Undefined array key "1.0E+121" in %s on line %d
NULL
Deprecated: Implicit conversion from float 1.0E+121 to int loses precision in %s on line %d
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d
string(1) "0"
Warning: Undefined array key "1.0E+121" in %s on line %d

View File

@@ -75,7 +75,10 @@ var_dump($string);
?>
--EXPECTF--
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d
int(0)
Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d
int(9223372036854775807)
Attempt to read
Float

View File

@@ -75,7 +75,10 @@ var_dump($string);
?>
--EXPECTF--
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d
int(0)
Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d
int(2147483647)
Attempt to read
Float

View File

@@ -17,14 +17,18 @@ foreach($values as $value) {
echo PHP_EOL;
}
?>
--EXPECT--
--EXPECTF--
float(0)
int(0)
float(INF)
Warning: The float INF is not representable as an int, cast occurred in %s on line %d
int(0)
float(-INF)
Warning: The float -INF is not representable as an int, cast occurred in %s on line %d
int(0)
float(0)
@@ -34,4 +38,6 @@ float(-0)
int(0)
float(NAN)
Warning: The float NAN is not representable as an int, cast occurred in %s on line %d
int(0)

View File

@@ -9939,14 +9939,14 @@ ZEND_API bool zend_is_op_long_compatible(const zval *op)
}
if (Z_TYPE_P(op) == IS_DOUBLE
&& !zend_is_long_compatible(Z_DVAL_P(op), zend_dval_to_lval(Z_DVAL_P(op)))) {
&& !zend_is_long_compatible(Z_DVAL_P(op), zend_dval_to_lval_silent(Z_DVAL_P(op)))) {
return false;
}
if (Z_TYPE_P(op) == IS_STRING) {
double dval = 0;
uint8_t is_num = is_numeric_str_function(Z_STR_P(op), NULL, &dval);
if (is_num == 0 || (is_num == IS_DOUBLE && !zend_is_long_compatible(dval, zend_dval_to_lval(dval)))) {
if (is_num == 0 || (is_num == IS_DOUBLE && !zend_is_long_compatible(dval, zend_dval_to_lval_silent(dval)))) {
return false;
}
}
@@ -9995,11 +9995,23 @@ ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, co
return 1;
}
if ((opcode == ZEND_MOD && zval_get_long(op2) == 0)
|| (opcode == ZEND_DIV && zval_get_double(op2) == 0.0)) {
/* Operation which cast float/float-strings to integers might produce incompatible float to int errors */
if (opcode == ZEND_SL || opcode == ZEND_SR || opcode == ZEND_BW_OR
|| opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR) {
return !zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2);
}
if (opcode == ZEND_DIV && zval_get_double(op2) == 0.0) {
/* Division by zero throws an error. */
return 1;
}
/* Mod is an operation that will cast float/float-strings to integers which might
produce float to int incompatible errors, and also cannot be divided by 0 */
if (opcode == ZEND_MOD) {
return !zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2) || zval_get_long(op2) == 0;
}
if ((opcode == ZEND_POW) && zval_get_double(op1) == 0 && zval_get_double(op2) < 0) {
/* 0 ** (<0) throws a division by zero error. */
return 1;
@@ -10009,12 +10021,6 @@ ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, co
return 1;
}
/* Operation which cast float/float-strings to integers might produce incompatible float to int errors */
if (opcode == ZEND_SL || opcode == ZEND_SR || opcode == ZEND_BW_OR
|| opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR || opcode == ZEND_MOD) {
return !zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2);
}
return 0;
}
/* }}} */
@@ -10166,7 +10172,7 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
zend_symtable_update(Z_ARRVAL_P(result), Z_STR_P(key), value);
break;
case IS_DOUBLE: {
zend_long lval = zend_dval_to_lval(Z_DVAL_P(key));
zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key));
/* Incompatible float will generate an error, leave this to run-time */
if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) {
zval_ptr_dtor_nogc(value);
@@ -12057,6 +12063,9 @@ bool zend_try_ct_eval_cast(zval *result, uint32_t type, zval *op1)
ZVAL_BOOL(result, zval_is_true(op1));
return true;
case IS_LONG:
if (Z_TYPE_P(op1) == IS_DOUBLE && !ZEND_DOUBLE_FITS_LONG(Z_DVAL_P((op1)))) {
return false;
}
ZVAL_LONG(result, zval_get_long(op1));
return true;
case IS_DOUBLE:

View File

@@ -1732,10 +1732,13 @@ try_again:
zend_illegal_string_offset(dim, type);
return 0;
}
case IS_DOUBLE:
/* Suppress potential double warning */
zend_error(E_WARNING, "String offset cast occurred");
return zend_dval_to_lval_silent(Z_DVAL_P(dim));
case IS_UNDEF:
ZVAL_UNDEFINED_OP2();
ZEND_FALLTHROUGH;
case IS_DOUBLE:
case IS_NULL:
case IS_FALSE:
case IS_TRUE:
@@ -2668,21 +2671,18 @@ static zend_never_inline uint8_t slow_index_convert(HashTable *ht, const zval *d
value->str = ZSTR_EMPTY_ALLOC();
return IS_STRING;
case IS_DOUBLE:
value->lval = zend_dval_to_lval(Z_DVAL_P(dim));
if (!zend_is_long_compatible(Z_DVAL_P(dim), value->lval)) {
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
}
zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
return IS_NULL;
}
if (EG(exception)) {
return IS_NULL;
}
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
}
value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
return IS_NULL;
}
if (EG(exception)) {
return IS_NULL;
}
return IS_LONG;
case IS_RESOURCE:
@@ -2753,23 +2753,20 @@ static zend_never_inline uint8_t slow_index_convert_w(HashTable *ht, const zval
value->str = ZSTR_EMPTY_ALLOC();
return IS_STRING;
case IS_DOUBLE:
value->lval = zend_dval_to_lval(Z_DVAL_P(dim));
if (!zend_is_long_compatible(Z_DVAL_P(dim), value->lval)) {
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
}
zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
if (!GC_REFCOUNT(ht)) {
zend_array_destroy(ht);
}
return IS_NULL;
}
if (EG(exception)) {
return IS_NULL;
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
}
value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
if (!GC_REFCOUNT(ht)) {
zend_array_destroy(ht);
}
return IS_NULL;
}
if (EG(exception)) {
return IS_NULL;
}
return IS_LONG;
case IS_RESOURCE:
@@ -3129,6 +3126,11 @@ try_string_offset:
return;
}
}
/* To prevent double warning */
if (Z_TYPE_P(dim) == IS_DOUBLE) {
offset = zend_dval_to_lval_silent(Z_DVAL_P(dim));
goto out;
}
break;
case IS_REFERENCE:
dim = Z_REFVAL_P(dim);
@@ -3239,7 +3241,17 @@ static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable
zend_ulong hval;
if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
return NULL;
}
if (EG(exception)) {
return NULL;
}
num_idx:
return zend_hash_index_find(ht, hval);
} else if (Z_TYPE_P(offset) == IS_NULL) {
@@ -3378,7 +3390,17 @@ num_key:
key = Z_REFVAL_P(key);
goto try_again;
} else if (Z_TYPE_P(key) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(key));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
return false;
}
if (EG(exception)) {
return false;
}
goto num_key;
} else if (Z_TYPE_P(key) == IS_FALSE) {
hval = 0;

View File

@@ -387,12 +387,9 @@ try_again:
return 1;
case IS_DOUBLE: {
double dval = Z_DVAL_P(op);
zend_long lval = zend_dval_to_lval(dval);
if (!zend_is_long_compatible(dval, lval)) {
zend_incompatible_double_to_long_error(dval);
if (UNEXPECTED(EG(exception))) {
*failed = 1;
}
zend_long lval = zend_dval_to_lval_safe(dval);
if (UNEXPECTED(EG(exception))) {
*failed = 1;
}
return lval;
}
@@ -418,6 +415,8 @@ try_again:
zend_error(E_WARNING, "A non-numeric value encountered");
if (UNEXPECTED(EG(exception))) {
*failed = 1;
zend_tmp_string_release(op_str);
return 0;
}
}
if (EXPECTED(type == IS_LONG)) {
@@ -428,14 +427,18 @@ try_again:
* We use use saturating conversion to emulate strtol()'s
* behaviour.
*/
lval = zend_dval_to_lval_cap(dval);
if (op_str == NULL) {
/* zend_dval_to_lval_cap() can emit a warning so always do the copy here */
op_str = zend_string_copy(Z_STR_P(op));
}
lval = zend_dval_to_lval_cap(dval, op_str);
if (!zend_is_long_compatible(dval, lval)) {
zend_incompatible_string_to_long_error(op_str ? op_str : Z_STR_P(op));
zend_incompatible_string_to_long_error(op_str);
if (UNEXPECTED(EG(exception))) {
*failed = 1;
}
}
zend_tmp_string_release(op_str);
zend_string_release(op_str);
return lval;
}
}
@@ -911,6 +914,14 @@ ZEND_API void ZEND_COLD zend_incompatible_string_to_long_error(const zend_string
{
zend_error(E_DEPRECATED, "Implicit conversion from float-string \"%s\" to int loses precision", ZSTR_VAL(s));
}
ZEND_API void ZEND_COLD zend_oob_double_to_long_error(double d)
{
zend_error_unchecked(E_WARNING, "The float %.*H is not representable as an int, cast occurred", -1, d);
}
ZEND_API void ZEND_COLD zend_oob_string_to_long_error(const zend_string *s)
{
zend_error_unchecked(E_WARNING, "The float-string \"%s\" is not representable as an int, cast occurred", ZSTR_VAL(s));
}
ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_strict) /* {{{ */
{
@@ -952,7 +963,7 @@ try_again:
* behaviour.
*/
/* Most usages are expected to not be (int) casts */
lval = zend_dval_to_lval_cap(dval);
lval = zend_dval_to_lval_cap(dval, Z_STR_P(op));
if (UNEXPECTED(is_strict)) {
if (!zend_is_long_compatible(dval, lval)) {
zend_incompatible_string_to_long_error(Z_STR_P(op));
@@ -1613,15 +1624,12 @@ try_again:
ZVAL_LONG(result, ~Z_LVAL_P(op1));
return SUCCESS;
case IS_DOUBLE: {
zend_long lval = zend_dval_to_lval(Z_DVAL_P(op1));
if (!zend_is_long_compatible(Z_DVAL_P(op1), lval)) {
zend_incompatible_double_to_long_error(Z_DVAL_P(op1));
if (EG(exception)) {
if (result != op1) {
ZVAL_UNDEF(result);
}
return FAILURE;
zend_long lval = zend_dval_to_lval_safe(Z_DVAL_P(op1));
if (EG(exception)) {
if (result != op1) {
ZVAL_UNDEF(result);
}
return FAILURE;
}
ZVAL_LONG(result, ~lval);
return SUCCESS;

View File

@@ -115,11 +115,28 @@ ZEND_API const char* ZEND_FASTCALL zend_memnrstr_ex(const char *haystack, const
# define ZEND_DOUBLE_FITS_LONG(d) (!((d) >= (double)ZEND_LONG_MAX || (d) < (double)ZEND_LONG_MIN))
#endif
ZEND_API void zend_incompatible_double_to_long_error(double d);
ZEND_API void zend_incompatible_string_to_long_error(const zend_string *s);
ZEND_API void ZEND_COLD zend_oob_double_to_long_error(double d);
ZEND_API void ZEND_COLD zend_oob_string_to_long_error(const zend_string *s);
ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d);
static zend_always_inline zend_long zend_dval_to_lval(double d)
{
if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) {
if (UNEXPECTED(!zend_finite(d))) {
zend_oob_double_to_long_error(d);
return 0;
} else if (!ZEND_DOUBLE_FITS_LONG(d)) {
zend_oob_double_to_long_error(d);
return zend_dval_to_lval_slow(d);
}
return (zend_long)d;
}
static zend_always_inline zend_long zend_dval_to_lval_silent(double d)
{
if (UNEXPECTED(!zend_finite(d))) {
return 0;
} else if (!ZEND_DOUBLE_FITS_LONG(d)) {
return zend_dval_to_lval_slow(d);
@@ -128,11 +145,13 @@ static zend_always_inline zend_long zend_dval_to_lval(double d)
}
/* Used to convert a string float to integer during an (int) cast */
static zend_always_inline zend_long zend_dval_to_lval_cap(double d)
static zend_always_inline zend_long zend_dval_to_lval_cap(double d, const zend_string *s)
{
if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) {
if (UNEXPECTED(!zend_finite(d))) {
zend_oob_string_to_long_error(s);
return 0;
} else if (!ZEND_DOUBLE_FITS_LONG(d)) {
zend_oob_string_to_long_error(s);
return (d > 0 ? ZEND_LONG_MAX : ZEND_LONG_MIN);
}
return (zend_long)d;
@@ -143,13 +162,10 @@ static zend_always_inline bool zend_is_long_compatible(double d, zend_long l) {
return (double)l == d;
}
ZEND_API void zend_incompatible_double_to_long_error(double d);
ZEND_API void zend_incompatible_string_to_long_error(const zend_string *s);
static zend_always_inline zend_long zend_dval_to_lval_safe(double d)
{
zend_long l = zend_dval_to_lval(d);
if (!zend_is_long_compatible(d, l)) {
if (!zend_is_long_compatible(d, l) && ZEND_DOUBLE_FITS_LONG(d)) {
zend_incompatible_double_to_long_error(d);
}
return l;

View File

@@ -6751,7 +6751,17 @@ ZEND_VM_C_LABEL(num_index_dim):
offset = Z_REFVAL_P(offset);
ZEND_VM_C_GOTO(offset_again);
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
ZEND_VM_C_GOTO(num_index_dim);
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();

120
Zend/zend_vm_execute.h generated
View File

@@ -26627,7 +26627,17 @@ num_index_dim:
offset = Z_REFVAL_P(offset);
goto offset_again;
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
goto num_index_dim;
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();
@@ -29168,7 +29178,17 @@ num_index_dim:
offset = Z_REFVAL_P(offset);
goto offset_again;
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
goto num_index_dim;
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();
@@ -33687,7 +33707,17 @@ num_index_dim:
offset = Z_REFVAL_P(offset);
goto offset_again;
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
goto num_index_dim;
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();
@@ -46191,7 +46221,17 @@ num_index_dim:
offset = Z_REFVAL_P(offset);
goto offset_again;
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
goto num_index_dim;
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();
@@ -50020,7 +50060,17 @@ num_index_dim:
offset = Z_REFVAL_P(offset);
goto offset_again;
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
goto num_index_dim;
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();
@@ -55769,7 +55819,17 @@ num_index_dim:
offset = Z_REFVAL_P(offset);
goto offset_again;
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
goto num_index_dim;
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();
@@ -81788,7 +81848,17 @@ num_index_dim:
offset = Z_REFVAL_P(offset);
goto offset_again;
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
goto num_index_dim;
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();
@@ -84329,7 +84399,17 @@ num_index_dim:
offset = Z_REFVAL_P(offset);
goto offset_again;
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
goto num_index_dim;
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();
@@ -88848,7 +88928,17 @@ num_index_dim:
offset = Z_REFVAL_P(offset);
goto offset_again;
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
goto num_index_dim;
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();
@@ -101352,7 +101442,17 @@ num_index_dim:
offset = Z_REFVAL_P(offset);
goto offset_again;
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
goto num_index_dim;
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();
@@ -105181,7 +105281,17 @@ num_index_dim:
offset = Z_REFVAL_P(offset);
goto offset_again;
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
goto num_index_dim;
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();
@@ -110828,7 +110938,17 @@ num_index_dim:
offset = Z_REFVAL_P(offset);
goto offset_again;
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {
/* The array may be destroyed while throwing a warning in case the float is not representable as an int.
* Temporarily increase the refcount to detect this situation. */
GC_TRY_ADDREF(ht);
hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
break;
}
if (EG(exception)) {
break;
}
goto num_index_dim;
} else if (Z_TYPE_P(offset) == IS_NULL) {
key = ZSTR_EMPTY_ALLOC();

View File

@@ -6,6 +6,7 @@ $payload = 'O:12:"DateInterval":9:{s:1:"y";i:1;s:1:"m";i:0;s:1:"d";i:4;s:1:"h";i
var_dump(unserialize($payload));
?>
--EXPECTF--
Warning: The float 9.99999999999E+18 is not representable as an int, cast occurred in %s on line %d
object(DateInterval)#%d (%d) {
["y"]=>
int(1)

View File

@@ -2261,7 +2261,7 @@ static bool dom_nodemap_or_nodelist_process_offset_as_named(zval *offset, zend_l
if (0 == (is_numeric_string_type = is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), lval, &dval, true))) {
return true;
} else if (is_numeric_string_type == IS_DOUBLE) {
*lval = zend_dval_to_lval_cap(dval);
*lval = zend_dval_to_lval_cap(dval, Z_STR_P(offset));
}
} else {
*lval = zval_get_long(offset);

View File

@@ -32,4 +32,4 @@ int(%d)
string(19) "America/Los_Angeles"
IntlDateFormatter::parseToCalendar(): Argument #2 ($offset) must be of type int, string given
Deprecated: Implicit conversion from float %r(1\.4757395258967641E\+20|34359738352)%r to int loses precision in %s on line %d
Warning: The float %r(1\.4757395258967641E\+20|34359738352)%r is not representable as an int, cast occurred in %s on line %d

View File

@@ -513,33 +513,30 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim,
}
return;
case IS_DOUBLE:
hval = zend_dval_to_lval(Z_DVAL_P(dim));
if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
}
execute_data = EG(current_execute_data);
opline = EX(opline);
zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
if (EG(exception)) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
} else {
ZVAL_NULL(EX_VAR(opline->result.var));
}
}
return;
}
if (EG(exception)) {
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
}
execute_data = EG(current_execute_data);
opline = EX(opline);
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
if (EG(exception)) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
} else {
ZVAL_NULL(EX_VAR(opline->result.var));
}
return;
}
return;
}
if (EG(exception)) {
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
}
return;
}
goto num_index;
case IS_RESOURCE:
@@ -663,33 +660,30 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim
return;
case IS_DOUBLE:
hval = zend_dval_to_lval(Z_DVAL_P(dim));
if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
}
execute_data = EG(current_execute_data);
opline = EX(opline);
zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
if (EG(exception)) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
} else {
ZVAL_NULL(EX_VAR(opline->result.var));
}
}
return;
}
if (EG(exception)) {
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
}
execute_data = EG(current_execute_data);
opline = EX(opline);
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
if (EG(exception)) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
} else {
ZVAL_NULL(EX_VAR(opline->result.var));
}
return;
}
return;
}
if (EG(exception)) {
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
}
return;
}
goto num_index;
case IS_RESOURCE:
@@ -799,21 +793,18 @@ static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *d
return result;
}
case IS_DOUBLE:
hval = zend_dval_to_lval(Z_DVAL_P(dim));
if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
}
zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
return 0;
}
if (EG(exception)) {
return 0;
}
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
}
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
zend_array_destroy(ht);
return 0;
}
if (EG(exception)) {
return 0;
}
goto num_index;
case IS_RESOURCE:
@@ -933,35 +924,32 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di
offset_key = ZSTR_EMPTY_ALLOC();
goto str_index;
case IS_DOUBLE:
hval = zend_dval_to_lval(Z_DVAL_P(dim));
if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
}
execute_data = EG(current_execute_data);
opline = EX(opline);
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
if (!GC_REFCOUNT(ht)) {
zend_array_destroy(ht);
}
execute_data = EG(current_execute_data);
opline = EX(opline);
zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
if (!GC_REFCOUNT(ht)) {
zend_array_destroy(ht);
}
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
if (EG(exception)) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
} else {
ZVAL_NULL(EX_VAR(opline->result.var));
}
}
return NULL;
}
if (EG(exception)) {
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
if (EG(exception)) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
} else {
ZVAL_NULL(EX_VAR(opline->result.var));
}
return NULL;
}
return NULL;
}
if (EG(exception)) {
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
}
return NULL;
}
goto num_index;
case IS_RESOURCE:
@@ -1096,35 +1084,32 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim
offset_key = ZSTR_EMPTY_ALLOC();
goto str_index;
case IS_DOUBLE:
hval = zend_dval_to_lval(Z_DVAL_P(dim));
if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
/* The array may be destroyed while throwing the notice.
* Temporarily increase the refcount to detect this situation. */
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(ht);
}
execute_data = EG(current_execute_data);
opline = EX(opline);
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
if (!GC_REFCOUNT(ht)) {
zend_array_destroy(ht);
}
execute_data = EG(current_execute_data);
opline = EX(opline);
zend_incompatible_double_to_long_error(Z_DVAL_P(dim));
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
if (!GC_REFCOUNT(ht)) {
zend_array_destroy(ht);
}
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
if (EG(exception)) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
} else {
ZVAL_NULL(EX_VAR(opline->result.var));
}
}
return NULL;
}
if (EG(exception)) {
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
if (EG(exception)) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
} else {
ZVAL_NULL(EX_VAR(opline->result.var));
}
return NULL;
}
return NULL;
}
if (EG(exception)) {
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
}
return NULL;
}
goto num_index;
case IS_RESOURCE:
@@ -1211,10 +1196,13 @@ try_again:
zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, BP_VAR_R);
return 0;
}
case IS_DOUBLE:
/* Suppress potential double warning */
zend_error(E_WARNING, "String offset cast occurred");
return zend_dval_to_lval_silent(Z_DVAL_P(dim));
case IS_UNDEF:
zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
ZEND_FALLTHROUGH;
case IS_DOUBLE:
case IS_NULL:
case IS_FALSE:
case IS_TRUE:
@@ -1286,14 +1274,17 @@ try_string_offset:
switch (Z_TYPE_P(dim)) {
/* case IS_LONG: */
case IS_STRING:
if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)) {
break;
if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, false)) {
goto out;
}
ZVAL_NULL(result);
return;
case IS_DOUBLE:
offset = zend_dval_to_lval_silent(Z_DVAL_P(dim));
goto out;
case IS_UNDEF:
zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
case IS_DOUBLE:
ZEND_FALLTHROUGH;
case IS_NULL:
case IS_FALSE:
case IS_TRUE:
@@ -1314,6 +1305,7 @@ try_string_offset:
offset = Z_LVAL_P(dim);
}
out:
if ((zend_ulong)offset >= (zend_ulong)ZSTR_LEN(str)) {
if (offset < 0) {
/* Handle negative offset */

View File

@@ -195,5 +195,6 @@ int(-9223371969208523780)
Warning: Undefined variable $u in %sadd_011.php on line 5
Deprecated: Implicit conversion from float %f to int loses precision in %sadd_011.php on line 5
int(66572500992)
Warning: The float %f is not representable as an int, cast occurred in %sadd_011.php on line 5
int(66572500992)

View File

@@ -11,7 +11,7 @@ $string_float= PHP_INT_MAX;
$a = [$float => 'a', $string_float => 'b', 'c', 'd'];
?>
--EXPECTF--
Deprecated: Implicit conversion from float 1.0E+38 to int loses precision in %sarray_elem_002.php on line 4
Warning: The float 1.0E+38 is not representable as an int, cast occurred in %sarray_elem_002.php on line 4
Fatal error: Uncaught Error: Cannot add element to the array as the next element is already occupied in %sarray_elem_002.php:4
Stack trace:

View File

@@ -20,5 +20,6 @@ function test() {
}
var_dump(test());
?>
--EXPECT--
--EXPECTF--
Warning: The float -1.8446744073709552E+19 is not representable as an int, cast occurred in %s on line %d
int(-3)

View File

@@ -20,5 +20,6 @@ function test() {
}
var_dump(test());
?>
--EXPECT--
--EXPECTF--
Warning: The float -1.8446744073709552E+19 is not representable as an int, cast occurred in %s on line %d
int(-10)

View File

@@ -23,5 +23,5 @@ function test($char_code) {
echo test(65), "\n";
?>
--EXPECTF--
Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d
correct

View File

@@ -10,8 +10,7 @@ $password = "openssl";
$ivlen = openssl_cipher_iv_length($method);
$iv = '';
srand(time() + ((int)(microtime(true) * 1000000) % 1000000));
while(strlen($iv) < $ivlen) $iv .= chr(rand(0,255));
while(strlen($iv) < $ivlen) $iv .= random_bytes(1);
$encrypted = openssl_encrypt($data, $method, $password, 0, $iv);
$output = openssl_decrypt($encrypted, $method, $password, 0, $iv);

View File

@@ -1219,7 +1219,7 @@ PHP_FUNCTION(min)
min_lval = Z_LVAL(args[i]);
min = &args[i];
}
} else if (Z_TYPE(args[i]) == IS_DOUBLE && (zend_dval_to_lval((double) min_lval) == min_lval)) {
} else if (Z_TYPE(args[i]) == IS_DOUBLE && (zend_dval_to_lval_silent((double) min_lval) == min_lval)) {
/* if min_lval can be exactly represented as a double, go to double dedicated code */
min_dval = (double) min_lval;
goto double_compare;
@@ -1239,7 +1239,7 @@ PHP_FUNCTION(min)
min_dval = Z_DVAL(args[i]);
min = &args[i];
}
} else if (Z_TYPE(args[i]) == IS_LONG && (zend_dval_to_lval((double) Z_LVAL(args[i])) == Z_LVAL(args[i]))) {
} else if (Z_TYPE(args[i]) == IS_LONG && (zend_dval_to_lval_silent((double) Z_LVAL(args[i])) == Z_LVAL(args[i]))) {
/* if the value can be exactly represented as a double, use double dedicated code otherwise generic */
if (min_dval > (double)Z_LVAL(args[i])) {
min_dval = (double)Z_LVAL(args[i]);
@@ -1277,7 +1277,7 @@ ZEND_FRAMELESS_FUNCTION(min, 2)
if (EXPECTED(Z_TYPE_P(rhs) == IS_LONG)) {
RETURN_COPY_VALUE(lhs_lval < Z_LVAL_P(rhs) ? lhs : rhs);
} else if (Z_TYPE_P(rhs) == IS_DOUBLE && (zend_dval_to_lval((double) lhs_lval) == lhs_lval)) {
} else if (Z_TYPE_P(rhs) == IS_DOUBLE && (zend_dval_to_lval_silent((double) lhs_lval) == lhs_lval)) {
/* if lhs_lval can be exactly represented as a double, go to double dedicated code */
lhs_dval = (double) lhs_lval;
goto double_compare;
@@ -1290,7 +1290,7 @@ ZEND_FRAMELESS_FUNCTION(min, 2)
if (EXPECTED(Z_TYPE_P(rhs) == IS_DOUBLE)) {
double_compare:
RETURN_COPY_VALUE(lhs_dval < Z_DVAL_P(rhs) ? lhs : rhs);
} else if (Z_TYPE_P(rhs) == IS_LONG && (zend_dval_to_lval((double) Z_LVAL_P(rhs)) == Z_LVAL_P(rhs))) {
} else if (Z_TYPE_P(rhs) == IS_LONG && (zend_dval_to_lval_silent((double) Z_LVAL_P(rhs)) == Z_LVAL_P(rhs))) {
/* if the value can be exactly represented as a double, use double dedicated code otherwise generic */
RETURN_COPY_VALUE(lhs_dval < (double)Z_LVAL_P(rhs) ? lhs : rhs);
} else {
@@ -1347,7 +1347,7 @@ PHP_FUNCTION(max)
max_lval = Z_LVAL(args[i]);
max = &args[i];
}
} else if (Z_TYPE(args[i]) == IS_DOUBLE && (zend_dval_to_lval((double) max_lval) == max_lval)) {
} else if (Z_TYPE(args[i]) == IS_DOUBLE && (zend_dval_to_lval_silent((double) max_lval) == max_lval)) {
/* if max_lval can be exactly represented as a double, go to double dedicated code */
max_dval = (double) max_lval;
goto double_compare;
@@ -1367,7 +1367,7 @@ PHP_FUNCTION(max)
max_dval = Z_DVAL(args[i]);
max = &args[i];
}
} else if (Z_TYPE(args[i]) == IS_LONG && (zend_dval_to_lval((double) Z_LVAL(args[i])) == Z_LVAL(args[i]))) {
} else if (Z_TYPE(args[i]) == IS_LONG && (zend_dval_to_lval_silent((double) Z_LVAL(args[i])) == Z_LVAL(args[i]))) {
/* if the value can be exactly represented as a double, use double dedicated code otherwise generic */
if (max_dval < (double)Z_LVAL(args[i])) {
max_dval = (double)Z_LVAL(args[i]);
@@ -1405,7 +1405,7 @@ ZEND_FRAMELESS_FUNCTION(max, 2)
if (EXPECTED(Z_TYPE_P(rhs) == IS_LONG)) {
RETURN_COPY_VALUE(lhs_lval >= Z_LVAL_P(rhs) ? lhs : rhs);
} else if (Z_TYPE_P(rhs) == IS_DOUBLE && (zend_dval_to_lval((double) lhs_lval) == lhs_lval)) {
} else if (Z_TYPE_P(rhs) == IS_DOUBLE && (zend_dval_to_lval_silent((double) lhs_lval) == lhs_lval)) {
/* if lhs_lval can be exactly represented as a double, go to double dedicated code */
lhs_dval = (double) lhs_lval;
goto double_compare;
@@ -1418,7 +1418,7 @@ ZEND_FRAMELESS_FUNCTION(max, 2)
if (EXPECTED(Z_TYPE_P(rhs) == IS_DOUBLE)) {
double_compare:
RETURN_COPY_VALUE(lhs_dval >= Z_DVAL_P(rhs) ? lhs : rhs);
} else if (Z_TYPE_P(rhs) == IS_LONG && (zend_dval_to_lval((double) Z_LVAL_P(rhs)) == Z_LVAL_P(rhs))) {
} else if (Z_TYPE_P(rhs) == IS_LONG && (zend_dval_to_lval_silent((double) Z_LVAL_P(rhs)) == Z_LVAL_P(rhs))) {
/* if the value can be exactly represented as a double, use double dedicated code otherwise generic */
RETURN_COPY_VALUE(lhs_dval >= (double)Z_LVAL_P(rhs) ? lhs : rhs);
} else {
@@ -2980,7 +2980,7 @@ PHP_FUNCTION(range)
is_step_negative = true;
step_double *= -1;
}
step = zend_dval_to_lval(step_double);
step = zend_dval_to_lval_silent(step_double);
if (!zend_is_long_compatible(step_double, step)) {
is_step_double = true;
}

View File

@@ -274,6 +274,7 @@ int(1)
string(7) "integer"
-- Iteration 20 --
string(6) "string"
2: The float-string "2974394749328742328432" is not representable as an int, cast occurred
bool(true)
int(2147483647)
string(7) "integer"
@@ -304,6 +305,7 @@ int(1)
string(7) "integer"
-- Iteration 26 --
string(6) "string"
2: The float-string "2974394749328742328432" is not representable as an int, cast occurred
bool(true)
int(2147483647)
string(7) "integer"
@@ -424,11 +426,13 @@ int(2147483647)
string(7) "integer"
-- Iteration 50 --
string(6) "double"
2: The float 2147483649 is not representable as an int, cast occurred
bool(true)
int(-2147483647)
string(7) "integer"
-- Iteration 51 --
string(6) "double"
2: The float 1232147483649 is not representable as an int, cast occurred
bool(true)
int(-508130303)
string(7) "integer"
@@ -439,6 +443,7 @@ int(85)
string(7) "integer"
-- Iteration 53 --
string(6) "double"
2: The float 1058513956921 is not representable as an int, cast occurred
bool(true)
int(1952002105)
string(7) "integer"
@@ -459,6 +464,7 @@ int(-365)
string(7) "integer"
-- Iteration 57 --
string(6) "double"
2: The float 80561044571754 is not representable as an int, cast occurred
bool(true)
int(343000682)
string(7) "integer"
@@ -669,6 +675,7 @@ int(1)
string(7) "integer"
-- Iteration 20 --
string(6) "string"
2: The float-string "2974394749328742328432" is not representable as an int, cast occurred
bool(true)
int(2147483647)
string(7) "integer"
@@ -699,6 +706,7 @@ int(1)
string(7) "integer"
-- Iteration 26 --
string(6) "string"
2: The float-string "2974394749328742328432" is not representable as an int, cast occurred
bool(true)
int(2147483647)
string(7) "integer"
@@ -819,11 +827,13 @@ int(2147483647)
string(7) "integer"
-- Iteration 50 --
string(6) "double"
2: The float 2147483649 is not representable as an int, cast occurred
bool(true)
int(-2147483647)
string(7) "integer"
-- Iteration 51 --
string(6) "double"
2: The float 1232147483649 is not representable as an int, cast occurred
bool(true)
int(-508130303)
string(7) "integer"
@@ -834,6 +844,7 @@ int(85)
string(7) "integer"
-- Iteration 53 --
string(6) "double"
2: The float 1058513956921 is not representable as an int, cast occurred
bool(true)
int(1952002105)
string(7) "integer"
@@ -854,6 +865,7 @@ int(-365)
string(7) "integer"
-- Iteration 57 --
string(6) "double"
2: The float 80561044571754 is not representable as an int, cast occurred
bool(true)
int(343000682)
string(7) "integer"

View File

@@ -94,13 +94,10 @@ $not_int_types = array (
array(),
array(0),
array(1),
array(NULL),
array(null),
array("string"),
array(true),
array(TRUE),
array(false),
array(FALSE),
array(1,2,3,4),
array(1 => "One", "two" => 2),
@@ -127,12 +124,6 @@ $not_int_types = array (
/* booleans */
true,
false,
TRUE,
FALSE,
/* undefined and unset vars */
@$unset_var,
@$undefined_var
);
@@ -230,11 +221,19 @@ int(-2147483648)
int(2147483647)
*** Testing intval() on non integer types ***
Warning: The float-string "-2147483649" is not representable as an int, cast occurred in %s on line %d
int(-2147483648)
Warning: The float-string "2147483648" is not representable as an int, cast occurred in %s on line %d
int(2147483647)
int(0)
int(0)
Warning: The float-string "020000000001" is not representable as an int, cast occurred in %s on line %d
int(2147483647)
Warning: The float-string "-020000000001" is not representable as an int, cast occurred in %s on line %d
int(-2147483648)
int(0)
int(0)
@@ -256,9 +255,6 @@ int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(0)
int(0)
int(0)
@@ -279,9 +275,5 @@ int(0)
int(0)
int(1)
int(0)
int(1)
int(0)
int(0)
int(0)
--- Done ---

View File

@@ -53,22 +53,22 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
echo "\n", toUTF8(65), "\n", toUTF8(233), "\n", toUTF8(1252), "\n", toUTF8(20095), "\n";
?>
--EXPECTF--
Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d
A
Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d
Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d
Warning: The float 4294965248 is not representable as an int, cast occurred in %s on line %d
é
Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d
Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d
Warning: The float 4294965248 is not representable as an int, cast occurred in %s on line %d
Ӥ
Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d
Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d
Warning: The float 4294965248 is not representable as an int, cast occurred in %s on line %d
Deprecated: Implicit conversion from float 4294901760 to int loses precision in %s on line %d
Warning: The float 4294901760 is not representable as an int, cast occurred in %s on line %d
乿

View File

@@ -23,12 +23,14 @@ printf("printf 64-bit signed int '18446744073709551615' (2^64)-1 = %u\n", 184467
echo "Done\n";
?>
--EXPECT--
--EXPECTF--
-Test
sscanf 32-bit signed int '2147483647' (2^31)-1 = 2147483647
sscanf 32-bit unsign int '4294967295' (2^32)-1 = 4294967295
sscanf 64-bit signed int '9223372036854775807' (2^63)-1 = 9223372036854775807
sscanf 64-bit unsign int '18446744073709551615' (2^64)-1 = 18446744073709551615
printf 64-bit signed int '9223372036854775807' (2^63)-1 = 9223372036854775807
Warning: The float 1.8446744073709552E+19 is not representable as an int, cast occurred in %s on line %d
printf 64-bit signed int '18446744073709551615' (2^64)-1 = 0
Done

View File

@@ -97,7 +97,7 @@ print_r(unpack("v", pack("v", -1000)));
print_r(unpack("v", pack("v", -64434)));
print_r(unpack("v", pack("v", -65535)));
?>
--EXPECT--
--EXPECTF--
Array
(
[1] => h
@@ -143,10 +143,14 @@ Array
(
[1] => -64434
)
Warning: The float 4294967296 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => 0
)
Warning: The float -4294967296 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => 0
@@ -159,10 +163,14 @@ Array
(
[1] => 0
)
Warning: The float 2147483650 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -2147483646
)
Warning: The float 4294967295 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -1
@@ -179,10 +187,14 @@ Array
(
[1] => 0
)
Warning: The float 2147483650 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -2147483646
)
Warning: The float 4294967296 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => 0
@@ -227,10 +239,14 @@ Array
(
[1] => 0
)
Warning: The float 2147483650 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -2147483646
)
Warning: The float 4294967296 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => 0
@@ -299,10 +315,14 @@ Array
(
[1] => 0
)
Warning: The float 2147483650 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -2147483646
)
Warning: The float 4294967296 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => 0

View File

@@ -37,7 +37,7 @@ print_r(unpack("i", pack("i", -2147483647)));
print_r(unpack("i", pack("i", -2147483648))); // Min int32
print_r(unpack("I", pack("I", 4294967295))); // Max uint32
?>
--EXPECT--
--EXPECTF--
Array
(
[1] => 281474976710654
@@ -46,6 +46,8 @@ Array
(
[1] => 0
)
Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -9223372036854775808
@@ -54,6 +56,8 @@ Array
(
[1] => -1
)
Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -9223372036854775808
@@ -66,6 +70,8 @@ Array
(
[1] => 0
)
Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -9223372036854775808
@@ -74,6 +80,8 @@ Array
(
[1] => -1
)
Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -9223372036854775808
@@ -86,6 +94,8 @@ Array
(
[1] => 0
)
Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -9223372036854775808
@@ -94,6 +104,8 @@ Array
(
[1] => -1
)
Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -9223372036854775808
@@ -106,6 +118,8 @@ Array
(
[1] => 0
)
Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -9223372036854775808
@@ -114,6 +128,8 @@ Array
(
[1] => -1
)
Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d
Array
(
[1] => -9223372036854775808

View File

@@ -74,10 +74,16 @@ foreach($args_array as $args) {
}
?>
--EXPECT--
--EXPECTF--
*** Testing vprintf() : octal formats and non-octal values ***
-- Iteration 1 --
Warning: The float 20000000000 is not representable as an int, cast occurred in %s on line %d
Warning: The float 2000000000000 is not representable as an int, cast occurred in %s on line %d
Warning: The float 22000000000000 is not representable as an int, cast occurred in %s on line %d
2 0 12
361100 37777775456 2322

View File

@@ -75,10 +75,16 @@ foreach($args_array as $args) {
}
?>
--EXPECT--
--EXPECTF--
*** Testing vprintf() : hexa formats and non-hexa values ***
-- Iteration 1 --
Warning: The float 20000000000 is not representable as an int, cast occurred in %s on line %d
Warning: The float 2000000000000 is not representable as an int, cast occurred in %s on line %d
Warning: The float 22000000000000 is not representable as an int, cast occurred in %s on line %d
2 0 a
1e240 x fffffb2e 4d2

View File

@@ -44,7 +44,7 @@ foreach($formats as $format) {
}
?>
--EXPECT--
--EXPECTF--
*** Testing vprintf() : unsigned formats and unsigned values ***
-- Iteration 1 --
@@ -52,10 +52,14 @@ foreach($formats as $format) {
int(16)
-- Iteration 2 --
Warning: The float 12345678900 is not representable as an int, cast occurred in %s on line %d
3755744308 1234 12345
int(21)
-- Iteration 3 --
Warning: The float 101234567000 is not representable as an int, cast occurred in %s on line %d
1234000 2450319192 120
int(25)

View File

@@ -44,7 +44,7 @@ foreach($formats as $format) {
}
?>
--EXPECT--
--EXPECTF--
*** Testing vprintf() : unsigned formats and unsigned values ***
-- Iteration 1 --
@@ -56,6 +56,8 @@ int(16)
int(22)
-- Iteration 3 --
Warning: The float 1.0E+21 is not representable as an int, cast occurred in %s on line %d
1234000 3875820019684212736 120
int(34)

View File

@@ -66,10 +66,16 @@ foreach($args_array as $args) {
$counter++;
}
?>
--EXPECT--
--EXPECTF--
*** Testing vprintf() : unsigned formats and signed & other types of values ***
-- Iteration 1 --
Warning: The float 20000000000 is not representable as an int, cast occurred in %s on line %d
Warning: The float 2000000000000 is not representable as an int, cast occurred in %s on line %d
Warning: The float 22000000000000 is not representable as an int, cast occurred in %s on line %d
2 0 10
123456 123456 1234
2820130816 2840207360 1177509888

View File

@@ -67,10 +67,12 @@ foreach($args_array as $args) {
}
?>
--EXPECT--
--EXPECTF--
*** Testing vprintf() : int formats and non-integer values ***
-- Iteration 1 --
Warning: The float 20000000000 is not representable as an int, cast occurred in %s on line %d
2 +0 10
123456 -1234 1234
-1474836480 200000 4000 22000000

View File

@@ -745,7 +745,7 @@ static inline void php_register_server_variables(void)
/* store request init time */
ZVAL_DOUBLE(&tmp, sapi_get_request_time());
php_register_variable_quick("REQUEST_TIME_FLOAT", sizeof("REQUEST_TIME_FLOAT")-1, &tmp, ht);
ZVAL_LONG(&tmp, zend_dval_to_lval(Z_DVAL(tmp)));
ZVAL_LONG(&tmp, zend_dval_to_lval_silent(Z_DVAL(tmp)));
php_register_variable_quick("REQUEST_TIME", sizeof("REQUEST_TIME")-1, &tmp, ht);
}
/* }}} */

View File

@@ -10,7 +10,7 @@ var_dump(-2147483648 % -2);
--EXPECTF--
int(0)
Deprecated: Implicit conversion from float -9.223372036860776E+18 to int loses precision in %s on line %d
Warning: The float -9.223372036860776E+18 is not representable as an int, cast occurred in %s on line %d
int(0)
int(0)
int(0)

View File

@@ -52,7 +52,7 @@ int(-4294967294)
int(-9223372036854775807)
--- testing: 9.2233720368548E+18 ---
Deprecated: Implicit conversion from float 9.223372036854776E+18 to int loses precision in %s on line %d
Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d
int(9223372036854775807)
--- testing: -9223372036854775807 ---
int(9223372036854775806)