Skip to content

Commit f1dd8b2

Browse files
committed
Make division by zero error check more accurate
For division (rather than modulus) we should check the double value, otherwise the result might be zero after integer truncation, but not zero as a floating point value.
1 parent 1ed132e commit f1dd8b2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Zend/zend_compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7259,7 +7259,8 @@ ZEND_API zend_bool zend_binary_op_produces_error(uint32_t opcode, zval *op1, zva
72597259
return 1;
72607260
}
72617261

7262-
if ((opcode == ZEND_DIV || opcode == ZEND_MOD) && zval_get_long(op2) == 0) {
7262+
if ((opcode == ZEND_MOD && zval_get_long(op2) == 0)
7263+
|| (opcode == ZEND_DIV && zval_get_double(op2) == 0.0)) {
72637264
/* Division by zero throws an error. */
72647265
return 1;
72657266
}

0 commit comments

Comments
 (0)