Skip to content

Commit fb57dda

Browse files
committed
Some fixes
Namely if deprecation notices are promoted to Exception due to an error handeler
1 parent b914543 commit fb57dda

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

Zend/tests/float_to_int/warnings_string_float_literals.phpt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ Deprecated: Implicit conversion to int from non-compatible float-string in %s on
7171

7272
Deprecated: Implicit conversion to int from non-compatible float-string in %s on line %d
7373

74-
Deprecated: Implicit conversion to int from non-compatible float-string in %s on line %d
75-
76-
Deprecated: Implicit conversion to int from non-compatible float-string in %s on line %d
77-
78-
Deprecated: Implicit conversion to int from non-compatible float-string in %s on line %d
79-
8074
Deprecated: Implicit conversion to int from non-compatible float-string in %s on line %d
8175
Bitwise ops:
8276
int(3)

Zend/zend_compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8014,12 +8014,12 @@ ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, zval *op1, zval *op
80148014
return 1;
80158015
}
80168016

8017-
if ((opcode == ZEND_MOD && zval_get_long(op2) == 0)
8017+
if ((opcode == ZEND_MOD && zval_get_long_func(op2, /* lax */ true) == 0)
80188018
|| (opcode == ZEND_DIV && zval_get_double(op2) == 0.0)) {
80198019
/* Division by zero throws an error. */
80208020
return 1;
80218021
}
8022-
if ((opcode == ZEND_SL || opcode == ZEND_SR) && zval_get_long(op2) < 0) {
8022+
if ((opcode == ZEND_SL || opcode == ZEND_SR) && zval_get_long_func(op2, /* lax */ true) < 0) {
80238023
/* Shift by negative number throws an error. */
80248024
return 1;
80258025
}

Zend/zend_operators.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,13 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(zval *op, bo
304304
case IS_TRUE:
305305
return 1;
306306
case IS_DOUBLE:
307-
return zend_dval_to_lval_safe(Z_DVAL_P(op));
307+
if (!is_long_compatible(Z_DVAL_P(op))) {
308+
zend_error(E_DEPRECATED, "Implicit conversion to int from non-compatible float");
309+
if (UNEXPECTED(EG(exception))) {
310+
*failed = 1;
311+
}
312+
}
313+
return zend_dval_to_lval(Z_DVAL_P(op));
308314
case IS_STRING:
309315
{
310316
zend_uchar type;
@@ -333,7 +339,13 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(zval *op, bo
333339
* We use use saturating conversion to emulate strtol()'s
334340
* behaviour.
335341
*/
336-
return zend_dval_to_lval_cap_safe(dval);
342+
if (!is_long_compatible(dval)) {
343+
zend_error(E_DEPRECATED, "Implicit conversion to int from non-compatible float-string");
344+
if (UNEXPECTED(EG(exception))) {
345+
*failed = 1;
346+
}
347+
}
348+
return zend_dval_to_lval_cap(dval);
337349
}
338350
}
339351
case IS_OBJECT:
@@ -452,6 +464,7 @@ ZEND_API void ZEND_FASTCALL convert_to_long(zval *op) /* {{{ */
452464
case IS_LONG:
453465
break;
454466
case IS_DOUBLE:
467+
// TODO Use safe variant?
455468
ZVAL_LONG(op, zend_dval_to_lval(Z_DVAL_P(op)));
456469
break;
457470
case IS_STRING:
@@ -800,6 +813,13 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_lax) /* {{
800813
case IS_LONG:
801814
return Z_LVAL_P(op);
802815
case IS_DOUBLE:
816+
if (EXPECTED(!is_lax)) {
817+
if (!is_long_compatible(Z_DVAL_P(op))) {
818+
zend_error(E_DEPRECATED, "Implicit conversion to int from non-compatible float");
819+
// TODO Need to handle this here?
820+
//if (UNEXPECTED(EG(exception))) {}
821+
}
822+
}
803823
return zend_dval_to_lval(Z_DVAL_P(op));
804824
case IS_STRING:
805825
{
@@ -816,11 +836,15 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_lax) /* {{
816836
* We use saturating conversion to emulate strtol()'s
817837
* behaviour.
818838
*/
819-
/* For (int) casts */
820-
if (UNEXPECTED(is_lax)) {
821-
return zend_dval_to_lval_cap(dval);
822-
}
823-
return zend_dval_to_lval_cap_safe(dval);
839+
/* Most usages are expected to not be (int) casts */
840+
if (EXPECTED(!is_lax)) {
841+
if (!is_long_compatible(dval)) {
842+
zend_error(E_DEPRECATED, "Implicit conversion to int from non-compatible float-string");
843+
// TODO Need to handle this here?
844+
//if (UNEXPECTED(EG(exception))) {}
845+
}
846+
}
847+
return zend_dval_to_lval_cap(dval);
824848
}
825849
}
826850
case IS_ARRAY:
@@ -1453,6 +1477,7 @@ ZEND_API zend_result ZEND_FASTCALL bitwise_not_function(zval *result, zval *op1)
14531477
ZVAL_LONG(result, ~Z_LVAL_P(op1));
14541478
return SUCCESS;
14551479
case IS_DOUBLE:
1480+
// TODO Handle manually in case deprecation notice promoted to Exception?
14561481
ZVAL_LONG(result, ~zend_dval_to_lval_safe(Z_DVAL_P(op1)));
14571482
return SUCCESS;
14581483
case IS_STRING: {

Zend/zend_operators.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,6 @@ static zend_always_inline zend_long zend_dval_to_lval_safe(double d)
145145
}
146146
return zend_dval_to_lval(d);
147147
}
148-
static zend_always_inline zend_long zend_dval_to_lval_cap_safe(double d)
149-
{
150-
if (!is_long_compatible(d)) {
151-
zend_error(E_DEPRECATED, "Implicit conversion to int from non-compatible float-string");
152-
}
153-
if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) {
154-
return 0;
155-
} else if (!ZEND_DOUBLE_FITS_LONG(d)) {
156-
return (d > 0 ? ZEND_LONG_MAX : ZEND_LONG_MIN);
157-
}
158-
return (zend_long)d;
159-
}
160148

161149
#define ZEND_IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
162150
#define ZEND_IS_XDIGIT(c) (((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f'))

0 commit comments

Comments
 (0)