From: Nikita Popov Date: Wed, 7 Jan 2015 22:21:12 +0000 (+0100) Subject: Fix the same leak with %= X-Git-Tag: PRE_PHP7_REMOVALS~31^2~11^2~10^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e826c97366044991ae3c892e00d607449f69d66;p=php Fix the same leak with %= --- diff --git a/Zend/tests/compound_shift_string_error.phpt b/Zend/tests/compound_assign_with_numeric_strings.phpt similarity index 74% rename from Zend/tests/compound_shift_string_error.phpt rename to Zend/tests/compound_assign_with_numeric_strings.phpt index 7f01962451..803650cb02 100644 --- a/Zend/tests/compound_shift_string_error.phpt +++ b/Zend/tests/compound_assign_with_numeric_strings.phpt @@ -19,7 +19,13 @@ $n = "-1"; $n >>= $n; var_dump($n); -?> +$n = "0"; +$n %= $n; +var_dump($n); + +$n = "-1"; +$n %= $n; +var_dump($n); --EXPECTF-- int(0) @@ -29,3 +35,7 @@ int(0) Warning: Bit shift by negative number in %s on line %d bool(false) + +Warning: Division by zero in %s on line %d +bool(false) +int(0) diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 31d92c4711..0b1b9f2188 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -1143,6 +1143,10 @@ ZEND_API int mod_function(zval *result, zval *op1, zval *op2) /* {{{ */ zend_long op1_lval, op2_lval; convert_op1_op2_long(op1, op1_lval, op2, op2_lval, ZEND_MOD, mod_function); + + if (op1 == result) { + zval_dtor(result); + } if (op2_lval == 0) { zend_error(E_WARNING, "Division by zero"); @@ -1156,9 +1160,6 @@ ZEND_API int mod_function(zval *result, zval *op1, zval *op2) /* {{{ */ return SUCCESS; } - if (op1 == result) { - zval_dtor(result); - } ZVAL_LONG(result, op1_lval % op2_lval); return SUCCESS; }