Skip to content

Commit 3e826c9

Browse files
committed
Fix the same leak with %=
1 parent 98c2cea commit 3e826c9

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Zend/tests/compound_shift_string_error.phpt renamed to Zend/tests/compound_assign_with_numeric_strings.phpt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ $n = "-1";
1919
$n >>= $n;
2020
var_dump($n);
2121

22-
?>
22+
$n = "0";
23+
$n %= $n;
24+
var_dump($n);
25+
26+
$n = "-1";
27+
$n %= $n;
28+
var_dump($n);
2329
--EXPECTF--
2430
int(0)
2531

@@ -29,3 +35,7 @@ int(0)
2935

3036
Warning: Bit shift by negative number in %s on line %d
3137
bool(false)
38+
39+
Warning: Division by zero in %s on line %d
40+
bool(false)
41+
int(0)

Zend/zend_operators.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,10 @@ ZEND_API int mod_function(zval *result, zval *op1, zval *op2) /* {{{ */
11431143
zend_long op1_lval, op2_lval;
11441144

11451145
convert_op1_op2_long(op1, op1_lval, op2, op2_lval, ZEND_MOD, mod_function);
1146+
1147+
if (op1 == result) {
1148+
zval_dtor(result);
1149+
}
11461150

11471151
if (op2_lval == 0) {
11481152
zend_error(E_WARNING, "Division by zero");
@@ -1156,9 +1160,6 @@ ZEND_API int mod_function(zval *result, zval *op1, zval *op2) /* {{{ */
11561160
return SUCCESS;
11571161
}
11581162

1159-
if (op1 == result) {
1160-
zval_dtor(result);
1161-
}
11621163
ZVAL_LONG(result, op1_lval % op2_lval);
11631164
return SUCCESS;
11641165
}

0 commit comments

Comments
 (0)