diff --git a/src/include/interval-map/interval-map.hh b/src/include/interval-map/interval-map.hh index ab3fb44..b518f24 100644 --- a/src/include/interval-map/interval-map.hh +++ b/src/include/interval-map/interval-map.hh @@ -35,7 +35,7 @@ public: if (insert_begin) it = underlying_.insert(it, {begin, val}); // Get the proper upper-bound for `end` - it = (it == underlying_.end()) ? it : std::next(it); + it = (it == underlying_.end() || end < it->first) ? it : std::next(it); if (!(at_upper_bound(it) == end_val)) underlying_.insert(it, {end, end_val}); } diff --git a/tests/unit/unit_test.cc b/tests/unit/unit_test.cc index c429d29..53675c3 100644 --- a/tests/unit/unit_test.cc +++ b/tests/unit/unit_test.cc @@ -242,6 +242,12 @@ TEST_F(IntervalMapTest, fuzzing_003) { assign(-110, -10, 4); } +TEST_F(IntervalMapTest, fuzzing_004) { + assign(-20, 120, 1); + assign(50, 110, 0); + assign(-120, 100, 0); +} + TEST_F(IntervalMapTest, randomized_test) { auto const seed = []() { std::random_device r;