Skip to content

Commit 86dc8aa

Browse files
committed
Add is_long_compatible func
1 parent 43f33ee commit 86dc8aa

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

Zend/Optimizer/sccp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ static inline int fetch_array_elem(zval **result, zval *op1, zval *op2) {
426426
*result = zend_hash_index_find(Z_ARR_P(op1), Z_LVAL_P(op2));
427427
return SUCCESS;
428428
case IS_DOUBLE:
429-
if ((double)(zend_long) Z_DVAL_P(op2) != Z_DVAL_P(op2)) {
429+
if (!is_long_compatible(Z_DVAL_P(op2))) {
430430
return FAILURE;
431431
}
432432
*result = zend_hash_index_find(Z_ARR_P(op1), zend_dval_to_lval(Z_DVAL_P(op2)));
@@ -512,7 +512,7 @@ static inline int ct_eval_del_array_elem(zval *result, zval *key) {
512512
zend_hash_index_del(Z_ARR_P(result), Z_LVAL_P(key));
513513
break;
514514
case IS_DOUBLE:
515-
if ((double)(zend_long) Z_DVAL_P(key) != Z_DVAL_P(key)) {
515+
if (!is_long_compatible(Z_DVAL_P(key))) {
516516
return FAILURE;
517517
}
518518
zend_hash_index_del(Z_ARR_P(result), zend_dval_to_lval(Z_DVAL_P(key)));
@@ -556,7 +556,7 @@ static inline int ct_eval_add_array_elem(zval *result, zval *value, zval *key) {
556556
break;
557557
case IS_DOUBLE:
558558
SEPARATE_ARRAY(result);
559-
if ((double)(zend_long) Z_DVAL_P(key) != Z_DVAL_P(key)) {
559+
if (!is_long_compatible(Z_DVAL_P(key))) {
560560
return FAILURE;
561561
}
562562
value = zend_hash_index_update(

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak(zval *arg, zend_long *dest,
504504

505505
/* This only checks for a fractional part as if doesn't fit it already throws a TypeError
506506
* Manually check to get correct warning text mentioning string origin */
507-
if ((double)(zend_long) d != d) {
507+
if (!is_long_compatible(d)) {
508508
zend_error(E_WARNING, "Implicit float string to int conversion");
509509
}
510510
*dest = zend_dval_to_lval(d);

Zend/zend_operators.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_lax) /* {{
818818
*/
819819
/* For (int) casts */
820820
if (UNEXPECTED(is_lax)) {
821-
return zend_dval_to_lval_cap(dval);
821+
return zend_dval_to_lval_cap(dval);
822822
}
823823
return zend_dval_to_lval_cap_safe(dval);
824824
}

Zend/zend_operators.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,20 @@ static zend_always_inline zend_long zend_dval_to_lval_cap(double d)
134134
}
135135
/* }}} */
136136

137+
static zend_always_inline bool is_long_compatible(double d) {
138+
return ((double)(zend_long) d == d);
139+
}
140+
137141
static zend_always_inline zend_long zend_dval_to_lval_safe(double d)
138142
{
139-
if ((double)(zend_long) d != d) {
143+
if (!is_long_compatible(d)) {
140144
zend_error(E_WARNING, "Implicit float to int conversion");
141145
}
142146
return zend_dval_to_lval(d);
143147
}
144148
static zend_always_inline zend_long zend_dval_to_lval_cap_safe(double d)
145149
{
146-
if ((double)(zend_long) d != d) {
150+
if (!is_long_compatible(d)) {
147151
zend_error(E_WARNING, "Implicit float string to int conversion");
148152
}
149153
if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) {

0 commit comments

Comments
 (0)