From 09bde2a5ef66884ab63f8649a15514840c03dd83 Mon Sep 17 00:00:00 2001
From: Mike Mackintosh <m@zyp.io>
Date: Sun, 22 Mar 2015 22:32:33 -0400
Subject: [PATCH] added bugfix/40 fix with test

---
 lib/ipaddress/ipv4.rb       | 7 ++-----
 test/ipaddress/ipv4_test.rb | 9 +++++++++
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb
index 6437810..fc2976a 100644
--- a/lib/ipaddress/ipv4.rb
+++ b/lib/ipaddress/ipv4.rb
@@ -1026,12 +1026,9 @@ module IPAddress;
     #
     private
 
+    # Tweaked to remove the #upto(32)
     def newprefix(num)
-      num.upto(32) do |i|
-        if (a = Math::log2(i).to_i) == Math::log2(i)
-          return @prefix + a 
-        end
-      end
+      return @prefix + (Math::log2(num).to_i)
     end
     
     def sum_first_found(arr)
diff --git a/test/ipaddress/ipv4_test.rb b/test/ipaddress/ipv4_test.rb
index bf969ad..e0b37b8 100644
--- a/test/ipaddress/ipv4_test.rb
+++ b/test/ipaddress/ipv4_test.rb
@@ -542,6 +542,15 @@ class IPv4Test < Minitest::Test
     assert_raises(ArgumentError){ @klass.parse_classful("192.168.256.257") }
   end
   
+  def test_network_split
+    @classful.each do |ip,net|
+      x = @klass.new("#{ip}/#{net}") 
+      assert_equal x.split(1).length, 1
+      assert_equal x.split(2).length, 2
+      assert_equal x.split(32).length, 32
+      assert_equal x.split(256).length, 256
+    end
+  end
 end # class IPv4Test
 
   
-- 
GitLab