Skip to content

Commit 96eb2f4

Browse files
committed
round(): Validate the rounding mode
1 parent 37ce719 commit 96eb2f4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ext/standard/math.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,17 @@ PHP_FUNCTION(round)
335335
}
336336
}
337337

338+
switch (mode) {
339+
case PHP_ROUND_HALF_UP:
340+
case PHP_ROUND_HALF_DOWN:
341+
case PHP_ROUND_HALF_EVEN:
342+
case PHP_ROUND_HALF_ODD:
343+
break;
344+
default:
345+
zend_argument_value_error(3, "must be a valid rounding mode (PHP_ROUND_*)");
346+
RETURN_THROWS();
347+
}
348+
338349
switch (Z_TYPE_P(value)) {
339350
case IS_LONG:
340351
/* Simple case - long that doesn't need to be rounded. */

0 commit comments

Comments
 (0)