diff options
-rw-r--r-- | ext/gmp/gmp.c | 7 | ||||
-rw-r--r-- | ext/gmp/tests/gmp_random_range.phpt | 4 |
2 files changed, 11 insertions, 0 deletions
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index 301729d563..2a6cc3d3c0 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -1871,6 +1871,13 @@ ZEND_FUNCTION(gmp_random_range) FETCH_GMP_ZVAL(gmpnum_min, min_arg, temp_a); FETCH_GMP_ZVAL(gmpnum_max, max_arg, temp_b); + if (mpz_cmp(gmpnum_min, gmpnum_max) > 0) { + FREE_GMP_TEMP(temp_a); + FREE_GMP_TEMP(temp_b); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The minimum value must be lower than the maximum value"); + return; + } + INIT_GMP_RETVAL(gmpnum_result); gmp_init_random(); diff --git a/ext/gmp/tests/gmp_random_range.phpt b/ext/gmp/tests/gmp_random_range.phpt index 93074f2913..50afafd4e9 100644 --- a/ext/gmp/tests/gmp_random_range.phpt +++ b/ext/gmp/tests/gmp_random_range.phpt @@ -5,7 +5,11 @@ gmp_random_range() basic tests --FILE-- <?php +var_dump(gmp_random_range(1, -1)); + echo "Done\n"; ?> --EXPECTF-- +Warning: gmp_random_range(): The minimum value must be lower than the maximum value in %s on line %d +NULL Done |