@@ -8156,6 +8156,27 @@ static bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast) /* {{{ */
8156
8156
}
8157
8157
/* }}} */
8158
8158
8159
+ ZEND_API bool zend_is_op_long_compatible (zval * op )
8160
+ {
8161
+ /* This is handled before */
8162
+ ZEND_ASSERT (Z_TYPE_P (op ) != IS_ARRAY );
8163
+
8164
+ if (Z_TYPE_P (op ) == IS_DOUBLE
8165
+ && !zend_is_long_compatible (Z_DVAL_P (op ), zend_dval_to_lval (Z_DVAL_P (op )))) {
8166
+ return false;
8167
+ }
8168
+
8169
+ if (Z_TYPE_P (op ) == IS_STRING ) {
8170
+ double dval = 0 ;
8171
+ zend_uchar is_num = is_numeric_str_function (Z_STR_P (op ), NULL , & dval );
8172
+ if (is_num == 0 || (is_num == IS_DOUBLE && !zend_is_long_compatible (dval , zend_dval_to_lval (dval )))) {
8173
+ return false;
8174
+ }
8175
+ }
8176
+
8177
+ return true;
8178
+ }
8179
+
8159
8180
ZEND_API bool zend_binary_op_produces_error (uint32_t opcode , zval * op1 , zval * op2 ) /* {{{ */
8160
8181
{
8161
8182
if ((opcode == ZEND_CONCAT || opcode == ZEND_FAST_CONCAT )) {
@@ -8210,13 +8231,7 @@ ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, zval *op1, zval *op
8210
8231
/* Operation which cast float/float-strings to integers might produce incompatible float to int errors */
8211
8232
if (opcode == ZEND_SL || opcode == ZEND_SR || opcode == ZEND_BW_OR
8212
8233
|| opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR || opcode == ZEND_MOD ) {
8213
- if (Z_TYPE_P (op1 ) == IS_DOUBLE || Z_TYPE_P (op2 ) == IS_DOUBLE ) {
8214
- return true;
8215
- }
8216
- if ((Z_TYPE_P (op1 ) == IS_STRING && is_numeric_str_function (Z_STR_P (op1 ), NULL , NULL ) != IS_LONG )
8217
- || (Z_TYPE_P (op2 ) == IS_STRING && is_numeric_str_function (Z_STR_P (op2 ), NULL , NULL ) != IS_LONG )) {
8218
- return true;
8219
- }
8234
+ return (!zend_is_op_long_compatible (op1 ) || !zend_is_op_long_compatible (op2 ));
8220
8235
}
8221
8236
8222
8237
return 0 ;
@@ -8238,7 +8253,7 @@ static inline bool zend_try_ct_eval_binary_op(zval *result, uint32_t opcode, zva
8238
8253
ZEND_API bool zend_unary_op_produces_error (uint32_t opcode , zval * op )
8239
8254
{
8240
8255
if (opcode == ZEND_BW_NOT ) {
8241
- return (Z_TYPE_P (op ) <= IS_TRUE || Z_TYPE_P (op ) == IS_ARRAY || Z_TYPE_P (op ) == IS_DOUBLE );
8256
+ return (Z_TYPE_P (op ) <= IS_TRUE || Z_TYPE_P (op ) == IS_ARRAY || ! zend_is_op_long_compatible (op ));
8242
8257
}
8243
8258
8244
8259
return 0 ;
0 commit comments