mirror of
https://github.com/php/php-src.git
synced 2024-09-22 10:27:25 +00:00
- Added test for bug #46587.
This commit is contained in:
parent
965c30dc2e
commit
1d5eff07f3
@ -315,18 +315,19 @@ PHP_FUNCTION(mt_rand)
|
||||
long number;
|
||||
int argc = ZEND_NUM_ARGS();
|
||||
|
||||
if (argc != 0 && zend_parse_parameters(argc TSRMLS_CC, "ll", &min, &max) == FAILURE)
|
||||
return;
|
||||
if (argc != 0) {
|
||||
if (zend_parse_parameters(argc TSRMLS_CC, "ll", &min, &max) == FAILURE) {
|
||||
return;
|
||||
} else if (max < min) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "max(%ld) is smaller than min(%ld)", max, min);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!BG(mt_rand_is_seeded)) {
|
||||
php_mt_srand(GENERATE_SEED() TSRMLS_CC);
|
||||
}
|
||||
|
||||
if (max < min) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "max(%ld) is smaller than min(%ld)", max, min);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Melo: hmms.. randomMT() returns 32 random bits...
|
||||
* Yet, the previous php_rand only returns 31 at most.
|
||||
|
16
ext/standard/tests/general_functions/bug46587.phpt
Normal file
16
ext/standard/tests/general_functions/bug46587.phpt
Normal file
@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Bug #46587 (mt_rand() does not check that max is greater than min).
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
var_dump(mt_rand(3,8));
|
||||
var_dump(mt_rand(8,3));
|
||||
|
||||
echo "Done.\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
int(%d)
|
||||
|
||||
Warning: mt_rand(): max(3) is smaller than min(8) in %s on line %d
|
||||
bool(false)
|
||||
Done.
|
Loading…
Reference in New Issue
Block a user