Fix retarded mistake in 57997, move break to within the if block or it defeats the...
[lhc/web/wiklou.git] / includes / Cdb_PHP.php
index b222909..49294f7 100644 (file)
@@ -17,7 +17,7 @@ class CdbFunctions {
         * $b must be less than 0x40000000 and greater than 0
         */
        public static function unsignedMod( $a, $b ) {
-               if ( $a 0 ) {
+               if ( $a & 0x80000000 ) {
                        $m = ( $a & 0x7fffffff ) % $b + 2 * ( 0x40000000 % $b );
                        return $m % $b;
                } else {
@@ -32,7 +32,7 @@ class CdbFunctions {
                if ( $b == 0 ) {
                        return $a;
                }
-               if ( $a 0 ) {
+               if ( $a & 0x80000000 ) {
                        return ( ( $a & 0x7fffffff ) >> $b ) | ( 0x40000000 >> ( $b - 1 ) );
                } else {
                        return $a >> $b;
@@ -45,20 +45,21 @@ class CdbFunctions {
        public static function hash( $s ) {
                $h = 5381;
                for ( $i = 0; $i < strlen( $s ); $i++ ) {
-                       $h5 = $h << 5;
+                       $h5 = ($h << 5) & 0xffffffff;
                        // Do a 32-bit sum
                        // Inlined here for speed
                        $sum = ($h & 0x3fffffff) + ($h5 & 0x3fffffff);
                        $h = 
                                (
                                        ( $sum & 0x40000000 ? 1 : 0 )
-                                       + ( $h 0 ? 2 : 0 )
+                                       + ( $h & 0x80000000 ? 2 : 0 )
                                        + ( $h & 0x40000000 ? 1 : 0 )
-                                       + ( $h5 0 ? 2 : 0 )
+                                       + ( $h5 & 0x80000000 ? 2 : 0 )
                                        + ( $h5 & 0x40000000 ? 1 : 0 )
                                ) << 30
                                | ( $sum & 0x3fffffff );
                        $h ^= ord( $s[$i] );
+                       $h &= 0xffffffff;
                }
                return $h;
        }
@@ -101,7 +102,8 @@ class CdbReader_PHP extends CdbReader {
        }
 
        function close() {
-               fclose( $this->handle );
+               if( isset($this->handle) )
+                       fclose( $this->handle );
                unset( $this->handle );
        }
 
@@ -250,7 +252,8 @@ class CdbWriter_PHP extends CdbWriter {
 
        public function close() {
                $this->finish();
-               fclose( $this->handle );
+               if( isset($this->handle) )
+                       fclose( $this->handle );
                if ( wfIsWindows() && file_exists($this->realFileName) ) {
                        unlink( $this->realFileName );
                }