Fix max(-1) is smaller than min(0) warning
authorReedy <reedy@wikimedia.org>
Thu, 30 Aug 2012 15:49:16 +0000 (16:49 +0100)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 4 Sep 2012 06:41:53 +0000 (06:41 +0000)
Warning:  mt_rand() [<a href='function.mt-rand'>function.mt-rand</a>]: 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

index c6ee03c6ddf76b155bc8c1cd8c88a2162c7cf276..27b6f2850c5546e2a286f1539b998c2be6884dac 100644 (file)
@@ -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;