From 881ab04b193c435604ce32b8180dbf6e8f00d689 Mon Sep 17 00:00:00 2001 From: Reedy Date: Thu, 30 Aug 2012 16:49:16 +0100 Subject: [PATCH] Fix max(-1) is smaller than min(0) warning Warning: mt_rand() [function.mt-rand]: max(-1) is smaller than min(0) in /usr/local/apache/common-local/php-1.20wmf10/extensions/ConfirmEdit/FancyCaptcha.class.php on line 135 Change-Id: I344504c133c84aea24ce38a4a4c05c2a0c12041b --- FancyCaptcha.class.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/FancyCaptcha.class.php b/FancyCaptcha.class.php index c6ee03c..27b6f28 100644 --- a/FancyCaptcha.class.php +++ b/FancyCaptcha.class.php @@ -132,7 +132,11 @@ class FancyCaptcha extends SimpleCaptcha { if ( !is_dir( $directory ) ) { return false; } - $n = mt_rand( 0, $this->countFiles( $directory ) - 1 ); + $dirCount = $this->countFiles( $directory ); + if ( $dirCount === 0 ) { + return false; + } + $n = mt_rand( 0, $dirCount - 1 ); $dir = opendir( $directory ); $count = 0; -- 2.39.5