Skip to content

Commit 32e94f0

Browse files
committed
Fix double deprecation notice in debug builds
Also fix memory exhaustion test text to be valid on prod builds
1 parent f476acd commit 32e94f0

8 files changed

+22
-28
lines changed

Zend/tests/float_to_int/warning_float_does_not_fit_zend_long_write_variation1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ Stack trace:
2525
#0 {main}
2626
thrown in %s on line %d
2727

28-
Fatal error: Allowed memory size of %d bytes exhausted at %s:141 (tried to allocate %d bytes) in %s on line %d
28+
Fatal error: Allowed memory size of %d bytes exhausted %S(tried to allocate %d bytes) in %s on line %d

Zend/tests/float_to_int/warning_float_does_not_fit_zend_long_write_variation2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ Stack trace:
2525
#0 {main}
2626
thrown in %s on line %d
2727

28-
Fatal error: Allowed memory size of %d bytes exhausted at %s:141 (tried to allocate %d bytes) in %s on line %d
28+
Fatal error: Allowed memory size of %d bytes exhausted %S(tried to allocate %d bytes) in %s on line %d

Zend/tests/float_to_int/warnings_float_literals.phpt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
Implicit float to int conversions should warn for literals
3-
--XFAIL--
4-
Double warning for internal calls
53
--FILE--
64
<?php
75

@@ -52,7 +50,6 @@ function foo(int $a) {
5250
}
5351
var_dump(foo(1.5));
5452

55-
// TODO: Why are two warnings generated here?
5653
var_dump(chr(60.5));
5754

5855
echo 'Function returns:' . \PHP_EOL;
@@ -130,8 +127,6 @@ Function calls:
130127
Deprecated: Implicit conversion to int from non-compatible float in %s on line %d
131128
int(1)
132129

133-
Deprecated: Implicit conversion to int from non-compatible float in %s on line %d
134-
135130
Deprecated: Implicit conversion to int from non-compatible float in %s on line %d
136131
string(1) "<"
137132
Function returns:

Zend/tests/float_to_int/warnings_float_vars.phpt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
Implicit float to int conversions should warn for variables
3-
--XFAIL--
4-
Double warning for internal calls
53
--FILE--
64
<?php
75

@@ -72,7 +70,6 @@ function foo(int $a) {
7270
}
7371
var_dump(foo($float));
7472

75-
// TODO: Why are two warnings generated here?
7673
$cp = 60.5;
7774
var_dump(chr($cp));
7875

@@ -159,8 +156,6 @@ Function calls:
159156
Deprecated: Implicit conversion to int from non-compatible float in %s on line %d
160157
int(1)
161158

162-
Deprecated: Implicit conversion to int from non-compatible float in %s on line %d
163-
164159
Deprecated: Implicit conversion to int from non-compatible float in %s on line %d
165160
string(1) "<"
166161
Function returns:

Zend/tests/float_to_int/warnings_string_float_literals.phpt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
Implicit string float to int conversions should warn for literals
3-
--XFAIL--
4-
Double warning for internal calls
53
--FILE--
64
<?php
75

@@ -35,7 +33,6 @@ function foo(int $a) {
3533
}
3634
var_dump(foo('1.5'));
3735

38-
// TODO: Why are two warnings generated here?
3936
var_dump(chr('60.5'));
4037

4138
echo 'Function returns:' . \PHP_EOL;
@@ -88,8 +85,6 @@ Function calls:
8885
Deprecated: Implicit conversion to int from non-compatible float-string in %s on line %d
8986
int(1)
9087

91-
Deprecated: Implicit conversion to int from non-compatible float-string in %s on line %d
92-
9388
Deprecated: Implicit conversion to int from non-compatible float-string in %s on line %d
9489
string(1) "<"
9590
Function returns:

Zend/tests/float_to_int/warnings_string_float_vars.phpt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
Implicit float string to int conversions should warn for variables
3-
--XFAIL--
4-
Double warning for internal calls
53
--FILE--
64
<?php
75

@@ -53,7 +51,6 @@ function foo(int $a) {
5351
}
5452
var_dump(foo($float));
5553

56-
// TODO: Why are two warnings generated here?
5754
$cp = '60.5';
5855
var_dump(chr($cp));
5956

@@ -115,8 +112,6 @@ Function calls:
115112
Deprecated: Implicit conversion to int from non-compatible float-string in %s on line %d
116113
int(1)
117114

118-
Deprecated: Implicit conversion to int from non-compatible float-string in %s on line %d
119-
120115
Deprecated: Implicit conversion to int from non-compatible float-string in %s on line %d
121116
string(1) "<"
122117
Function returns:

Zend/zend_API.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,15 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak(zval *arg, zend_long *dest,
487487
if (UNEXPECTED(!ZEND_DOUBLE_FITS_LONG(Z_DVAL_P(arg)))) {
488488
return 0;
489489
} else {
490-
*dest = zend_dval_to_lval_safe(Z_DVAL_P(arg));
490+
/* Manually check arg_num is not (uint32_t)-1, as otherwise its called by
491+
* zend_verify_weak_scalar_type_hint_no_sideeffect() */
492+
if (UNEXPECTED(!is_long_compatible(Z_DVAL_P(arg)) && arg_num != (uint32_t)-1)) {
493+
zend_error(E_DEPRECATED, "Implicit conversion to int from non-compatible float");
494+
if (UNEXPECTED(EG(exception))) {
495+
return 0;
496+
}
497+
}
498+
*dest = zend_dval_to_lval(Z_DVAL_P(arg));
491499
}
492500
} else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
493501
double d;
@@ -503,9 +511,14 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak(zval *arg, zend_long *dest,
503511
}
504512

505513
/* This only checks for a fractional part as if doesn't fit it already throws a TypeError
506-
* Manually check to get correct warning text mentioning string origin */
507-
if (!is_long_compatible(d)) {
514+
* Manually check to get correct warning text mentioning string origin
515+
* Check arg_num is not (uint32_t)-1, as otherwise its called by
516+
* zend_verify_weak_scalar_type_hint_no_sideeffect() */
517+
if (UNEXPECTED(!is_long_compatible(d) && arg_num != (uint32_t)-1)) {
508518
zend_error(E_DEPRECATED, "Implicit conversion to int from non-compatible float-string");
519+
if (UNEXPECTED(EG(exception))) {
520+
return 0;
521+
}
509522
}
510523
*dest = zend_dval_to_lval(d);
511524
} else {

Zend/zend_execute.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,16 +781,17 @@ static bool zend_verify_weak_scalar_type_hint_no_sideeffect(uint32_t type_mask,
781781
double dval;
782782
bool bval;
783783

784-
if ((type_mask & MAY_BE_LONG) && zend_parse_arg_long_weak(arg, &lval, 0)) {
784+
/* Pass (uint32_t)-1 as arg_num to indicate to ZPP not to emit any deprecation notice */
785+
if ((type_mask & MAY_BE_LONG) && zend_parse_arg_long_weak(arg, &lval, (uint32_t)-1)) {
785786
return 1;
786787
}
787-
if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, 0)) {
788+
if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, (uint32_t)-1)) {
788789
return 1;
789790
}
790791
if ((type_mask & MAY_BE_STRING) && can_convert_to_string(arg)) {
791792
return 1;
792793
}
793-
if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, 0)) {
794+
if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, (uint32_t)-1)) {
794795
return 1;
795796
}
796797
return 0;

0 commit comments

Comments
 (0)