X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/03f2fa83c13c1b532284205fa7efcab9b8b2c41f..refs/tags/wordpress-4.5:/wp-includes/random_compat/random_int.php diff --git a/wp-includes/random_compat/random_int.php b/wp-includes/random_compat/random_int.php index 6c91dbc5..fd3ef87a 100644 --- a/wp-includes/random_compat/random_int.php +++ b/wp-includes/random_compat/random_int.php @@ -55,6 +55,7 @@ function random_int($min, $max) 'random_int(): $min must be an integer' ); } + try { $max = RandomCompat_intval($max); } catch (TypeError $ex) { @@ -73,6 +74,7 @@ function random_int($min, $max) 'Minimum value must be less than or equal to the maximum value' ); } + if ($max === $min) { return $min; } @@ -98,6 +100,7 @@ function random_int($min, $max) * Test for integer overflow: */ if (!is_int($range)) { + /** * Still safely calculate wider ranges. * Provided by @CodesInChaos, @oittaa @@ -111,7 +114,9 @@ function random_int($min, $max) */ $bytes = PHP_INT_SIZE; $mask = ~0; + } else { + /** * $bits is effectively ceil(log($range, 2)) without dealing with * type juggling @@ -181,5 +186,6 @@ function random_int($min, $max) * then try again. */ } while (!is_int($val) || $val > $max || $val < $min); + return (int) $val; }