diff --git a/persistent-data/data-structures/btree_damage_visitor.h b/persistent-data/data-structures/btree_damage_visitor.h index ca4a069..2e248e8 100644 --- a/persistent-data/data-structures/btree_damage_visitor.h +++ b/persistent-data/data-structures/btree_damage_visitor.h @@ -70,10 +70,17 @@ namespace persistent_data { } maybe_run64 end() { + maybe_run64 r; + if (damaged_) - return maybe_run64(damage_begin_); + r = maybe_run64(damage_begin_); else - return maybe_run64(); + r = maybe_run64(); + + damaged_ = false; + damage_begin_ = 0; + + return r; } private: diff --git a/unit-tests/damage_tracker_t.cc b/unit-tests/damage_tracker_t.cc index a2f54a4..f211592 100644 --- a/unit-tests/damage_tracker_t.cc +++ b/unit-tests/damage_tracker_t.cc @@ -98,4 +98,15 @@ TEST_F(DamageTrackerTests, gi_bi_gi_bl_gl) assert_damage(dt.good_leaf(15, 20), run64(10ull, 15ull)); } +TEST_F(DamageTrackerTests, end_resets_tracker) +{ + dt.good_internal(0); + dt.good_leaf(0, 10); + dt.bad_node(); + assert_damage(dt.end(), run64(10ull)); + + assert_no_damage(dt.good_leaf(20, 30)); + assert_no_damage(dt.end()); +} + //----------------------------------------------------------------