Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Zend/Optimizer/sccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions Zend/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bitwise_not_precision_exception.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions Zend/tests/bug46701.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug78340.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class lib {

function stream_stat() {
return [
'dev' => 3632233996,
'dev' => PHP_INT_MAX,
'size' => strlen($this->bytes),
'ino' => $this->ino
];
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/falsetoarray_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion Zend/tests/int_overflow_32bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion Zend/tests/int_overflow_64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion Zend/tests/int_underflow_32bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
89 changes: 89 additions & 0 deletions Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
89 changes: 89 additions & 0 deletions Zend/tests/offsets/array_container_offset_behaviour.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
) {
Expand Down Expand Up @@ -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
) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Loading