From c9ece323029a5a85cf9ba34d9b65471f8b93b039 Mon Sep 17 00:00:00 2001 From: Simon Erni Date: Thu, 13 Jun 2019 17:44:06 +0200 Subject: [PATCH 1/2] - Fixed Bug when generating a large amount of subnets from a large subnet - Root Cause: Integer Overflow - Simplified maxSubnets calculation in the same step --- src/main/scala/com/risksense/ipaddr/IpNetwork.scala | 3 +-- src/test/scala/com/risksense/ipaddr/IpNetworkTest.scala | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/scala/com/risksense/ipaddr/IpNetwork.scala b/src/main/scala/com/risksense/ipaddr/IpNetwork.scala index 5fa393d..17ea695 100644 --- a/src/main/scala/com/risksense/ipaddr/IpNetwork.scala +++ b/src/main/scala/com/risksense/ipaddr/IpNetwork.scala @@ -181,8 +181,7 @@ class IpNetwork private[ipaddr]( if (prefix < 0 || prefix > this.ipAddr.width || prefix < this.mask) { Nil } else { - val maxSubnets = scala.math.pow(2, this.ipAddr.width - this.mask).toInt / - scala.math.pow(2, this.ipAddr.width - prefix).toInt + val maxSubnets = scala.math.pow(2, prefix - this.mask).toInt val countNew = count match { case 0 => maxSubnets case _ => count diff --git a/src/test/scala/com/risksense/ipaddr/IpNetworkTest.scala b/src/test/scala/com/risksense/ipaddr/IpNetworkTest.scala index bb87fd9..24983f3 100644 --- a/src/test/scala/com/risksense/ipaddr/IpNetworkTest.scala +++ b/src/test/scala/com/risksense/ipaddr/IpNetworkTest.scala @@ -74,6 +74,12 @@ class IpNetworkTest extends UnitSpec { net1.subnet(26).size should be(4) // scalastyle:ignore net1.subnet(26).size should be(4) net1.subnet(33) should be(Nil) + + val largeAmountOfSubnets = net6.subnet(17, 100000) + + largeAmountOfSubnets.size should be (100000) + largeAmountOfSubnets.forall(s => s.mask == 17) should be(true) + } it should "perform next operation" in { From 1bf65c3eacd807ff19dd0a35287bb0f574b72a49 Mon Sep 17 00:00:00 2001 From: Simon Erni Date: Thu, 13 Jun 2019 17:53:40 +0200 Subject: [PATCH 2/2] Bump Version number to 1.0.3 --- README.md | 2 +- build.sbt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 699f6b4..87402c7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ library for Python. Examples in this readme are taken from [here](https://netadd ## Usage Add the following to your build.sbt: -`libraryDependencies += "com.risksense" % "ipaddr_2.12" % "1.0.2"` +`libraryDependencies += "com.risksense" % "ipaddr_2.12" % "1.0.3"` ## Tutorial * [IpAddress](#ipaddress) diff --git a/build.sbt b/build.sbt index 768c405..64b8b5b 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,7 @@ lazy val root = (project in file(".")) .settings( name := "ipaddr", organization := "com.risksense", - version := "1.0.2", + version := "1.0.3", scalaVersion := "2.12.6", scalacOptions ++= Seq( "-feature",