From 801110dd17bb349c9456ccc9046463529d09c3ee Mon Sep 17 00:00:00 2001 From: HMBSbige Date: Wed, 4 Jul 2018 15:28:44 +0800 Subject: [PATCH] Fix bugs --- IPExt.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/IPExt.cs b/IPExt.cs index 3057700..fd195e6 100644 --- a/IPExt.cs +++ b/IPExt.cs @@ -48,7 +48,7 @@ public static string[] Find(string ip) var start = index[ip_prefix_value]; var max_comp_len = offset - 262144 - 4; long index_offset = -1; - var index_length = -1; + long index_length = -1; byte b = 0; for (start = start * 9 + 262144; start < max_comp_len; start += 9) { @@ -58,7 +58,7 @@ public static string[] Find(string ip) { index_offset = BytesToLong(b, indexBuffer[start + 6], indexBuffer[start + 5], indexBuffer[start + 4]); - index_length = (0xFF & indexBuffer[start + 7] << 8) + indexBuffer[start + 8]; + index_length = BytesToLong(b, b, indexBuffer[start + 7], indexBuffer[start + 8]); break; } } @@ -100,7 +100,7 @@ private static void Load() var indexLength = BytesToLong(dataBuffer[0], dataBuffer[1], dataBuffer[2], dataBuffer[3]); indexBuffer = new byte[indexLength]; - Array.Copy(dataBuffer, 4, indexBuffer, 0, indexLength); + Array.Copy(dataBuffer, 4, indexBuffer, 0, dataBuffer.Length - 4); offset = (int)indexLength; for (var i = 0; i < 256; i++)