Bugfix in generate random string.
[squirrelmail.git] / functions / strings.php
index 4481bd6ba5643f53cff2b3dafc25b5cb973084dc..e9bac3f31b7cf5a15e41f10bc2627bfdb638060f 100644 (file)
@@ -209,8 +209,9 @@ function translateText(&$body, $wrap_at, $charset) {
 
         $Quotes = 0;
         $pos = 0;
+       $j = strlen( $line );
 
-        while ( $line <> '' ) {
+        while ( $pos < $j ) {
             if ($line[$pos] == ' ') {
                 $pos ++;
             } else if (strpos($line, '&gt;', $pos) === $pos) {
@@ -538,14 +539,15 @@ function GenerateRandomString($size, $chars, $flags = 0) {
     if (($size < 1) || (strlen($chars) < 1)) {
         return '';
     }
-    
+
     sq_mt_randomize(); /* Initialize the random number generator */
-    
+
     $String = '';
+    $j = strlen( $chars ) - 1;
     while (strlen($String) < $size) {
-        $String .= $chars[mt_rand(0, strlen($chars))];
+        $String .= $chars{mt_rand(0, $j)};
     }
-    
+
     return $String;
 }