This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-12
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 851134059d6cb9319f831a988f937bd5a773a969
Author: Alan M. Carroll <a...@apache.org>
AuthorDate: Fri Feb 21 13:52:44 2020 -0600

    Fix non-terminating loop bug in IPSpace::mark, add unit tests to verify.
---
 swoc++/include/swoc/DiscreteRange.h |  2 ++
 unit_tests/test_ip.cc               | 26 +++++++++++++++++++-------
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/swoc++/include/swoc/DiscreteRange.h 
b/swoc++/include/swoc/DiscreteRange.h
index 9ea907f..d74dd7e 100644
--- a/swoc++/include/swoc/DiscreteRange.h
+++ b/swoc++/include/swoc/DiscreteRange.h
@@ -1071,6 +1071,8 @@ DiscreteSpace<METRIC, 
PAYLOAD>::mark(DiscreteSpace::range_type const &range, PAY
     } else if (n->min() <= range.max()) { // skew overlap different payload
       n->assign_min(max_plus_1);
       break;
+    } else { // n->min() > range.max(), different payloads - done.
+      break;
     }
   }
 
diff --git a/unit_tests/test_ip.cc b/unit_tests/test_ip.cc
index 582b531..e3b5d74 100644
--- a/unit_tests/test_ip.cc
+++ b/unit_tests/test_ip.cc
@@ -266,13 +266,6 @@ TEST_CASE("IP Formatting", "[libswoc][ip][bwformat]") {
 TEST_CASE("IP Space Int", "[libswoc][ip][ipspace]") {
   using int_space = swoc::IPSpace<unsigned>;
   int_space space;
-  auto dump = [](int_space&space) -> void {
-    swoc::LocalBufferWriter<1024> w;
-    std::cout << "Dumping " << space.count() << " ranges" << std::endl;
-    for (auto &&[r, payload] : space) {
-      std::cout << w.clear().print("{} - {} : {}\n", r.min(), r.max(), 
payload).view();
-    }
-  };
 
   REQUIRE(space.count() == 0);
 
@@ -337,6 +330,25 @@ TEST_CASE("IP Space Int", "[libswoc][ip][ipspace]") {
 
   space.blend({r_2.min(), r_3.max()}, 0x6, BF);
   REQUIRE(space.count() == 4);
+
+  std::array<std::tuple<TextView, int>, 9> ranges = {
+      {
+          { "100.0.0.0-100.0.0.255",  0 }
+          , { "100.0.1.0-100.0.1.255",  1 }
+          , { "100.0.2.0-100.0.2.255",  2 }
+          , { "100.0.3.0-100.0.3.255",  3 }
+          , { "100.0.4.0-100.0.4.255",  4 }
+          , { "100.0.5.0-100.0.5.255",  5 }
+          , { "100.0.6.0-100.0.6.255",  6 }
+          , { "100.0.0.0-100.0.0.255",  31 }
+          , { "100.0.1.0-100.0.1.255",  30 }
+      }};
+
+  space.clear();
+  for (auto &&[text, value] : ranges) {
+    space.mark(IPRange{text}, value);
+  }
+  CHECK(7 == space.count());
 }
 
 TEST_CASE("IPSpace bitset", "[libswoc][ipspace][bitset]") {

Reply via email to