From f1dd8b2af08829a41df072cd9a2bf4a2d82b3ec9 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 1 Apr 2020 14:47:21 +0200 Subject: [PATCH] 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. --- Zend/zend_compile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 914f991bac4..1f0c6325bd2 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -7259,7 +7259,8 @@ ZEND_API zend_bool zend_binary_op_produces_error(uint32_t opcode, zval *op1, zva return 1; } - if ((opcode == ZEND_DIV || opcode == ZEND_MOD) && zval_get_long(op2) == 0) { + if ((opcode == ZEND_MOD && zval_get_long(op2) == 0) + || (opcode == ZEND_DIV && zval_get_double(op2) == 0.0)) { /* Division by zero throws an error. */ return 1; }