Merge "Added comment about not using ignoreErrors()"
[lhc/web/wiklou.git] / includes / IP.php
index 0a8faa2..fc76310 100644 (file)
@@ -212,7 +212,7 @@ class IP {
                                        $longest = $match;
                                        $longestPos = $pos;
                                }
-                               $offset += ( $pos + strlen( $match ) ); // advance
+                               $offset = ( $pos + strlen( $match ) ); // advance
                        }
                        if ( $longest !== false ) {
                                // Replace this portion of the string with the '::' abbreviation
@@ -492,6 +492,11 @@ class IP {
                        $n = ip2long( $ip );
                        if ( $n < 0 ) {
                                $n += pow( 2, 32 );
+                               # On 32-bit platforms (and on Windows), 2^32 does not fit into an int,
+                               # so $n becomes a float. We convert it to string instead.
+                               if ( is_float( $n ) ) {
+                                       $n = (string)$n;
+                               }
                        }
                }
                return $n;
@@ -526,7 +531,7 @@ class IP {
                        if ( $bits == 0 ) {
                                $network = 0;
                        } else {
-                               $network &= ~( ( 1 << ( 32 - $bits ) ) - 1);
+                               $network &= ~( ( 1 << ( 32 - $bits ) ) - 1 );
                        }
                        # Convert to unsigned
                        if ( $network < 0 ) {