Fix max(-1) is smaller than min(0) warning
[toast/cookiecaptcha.git] / 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;